These are chat archives for FreeCodeCamp/Help

21st
Sep 2018
psyperl
@psyperl
Sep 21 2018 00:00

assume one destruct things like

const firstLetter = ([x]) => x
firstLetter ("test")

wish it can do operation on the desctructed var directly like

const firstLetter = ([ x.toUpperCase() ]) => x
firstLetter ("test")
dpinney39
@dpinney39
Sep 21 2018 00:44

<style>
h4 {
text-align: center;
height: 25px;
}
p {
text-align: justify;
font-weight: bold;
}
.links {
text-align: left;
color: black;
}
.fullCard {
width: 245px;
border: 1px solid #ccc;
border-radius: 5px;
margin: 10px 5px;
padding: 4px;
}
.cardContent {
padding: 10px;
}
.cardText {
margin-bottom: 30px;
}
</style>

<div class="fullCard">
<div class="cardContent">
<div class="cardText">
<h4>Google</h4>
<strong>
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D. students at <strong> Stanford University.</strong></p>
</div>
<div class="cardLinks">
<a href="https://en.wikipedia.org/wiki/Larry_Page" target="_blank" class="links">Larry Page</a><br><br>
<a href="https://en.wikipedia.org/wiki/Sergey_Brin" target="_blank" class="links">Sergey Brin</a>
</div>
</div>
</div>
Your code should add one strong tag to the markup.
The strong tag should be inside the p tag.
The strong tag should wrap around the words "Stanford University".

learningjs42
@learningjs42
Sep 21 2018 01:06
hello all i have a question why i need to make 2 requests to get the responseText why i can not reuse ?
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
          if (this.readyState == 4 && this.status == 200) {
            console.log(xhttp.responseText)
          }
      };
      var xhttp2 = new XMLHttpRequest();
      xhttp2.onreadystatechange = function() {
          if (this.readyState == 4 && this.status == 200) {
            console.log(xhttp2.responseText)
          }
      };
      xhttp.open("GET", "people.json", true);
      xhttp.send();

      xhttp2.open("GET", "test.json", true);
      xhttp2.send();
Eunice Park
@eunicode
Sep 21 2018 01:43
@learningjs42 The first XHR request is requesting data from "people.json", and the second XHR request is requesting data from "test.json". The XHR object's open property has information like the URL we want to send to the server. If this information is different, like the URL, you need to create a new XHR request/object.
Jun Yada
@junyada100
Sep 21 2018 01:52
@learningjs42 XMLHttpRequest is async, if you try to reuse, it will abort the first one; from your code if you use xhttp (not xhttp2) to get test.json, it will abort get people.json. and you will never get responseText from people.json.
Aditya
@ezioda004
Sep 21 2018 03:05
@dpinney39 You have an extra <strong>before <p>Google..
Aditya
@ezioda004
Sep 21 2018 03:46
@learningjs42 You can reuse by doing something like
function load(url){
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      console.log(xhttp.responseText)
    }
  };
  xhttp.open("GET", url, true);
  xhttp.send();
}
load("people.json");
load("test.json");
The order however wont be guaranteed, using callbacks will resolve that
黄俊
@DYLANFREE
Sep 21 2018 04:23
code:<a href=“https://v.qq.com/x/page/q0177lf39h5.html” target=_blank></a>
problem:
i can't not open this website in codepen.It warns me 404,why and what should i do?
Claudio Restifo
@Marmiz
Sep 21 2018 04:25
target=_blank // missing quotes
target="_blank"
黄俊
@DYLANFREE
Sep 21 2018 04:27
i get it,thanks.this[“”] wrong,[""]right @Marmiz
Claudio Restifo
@Marmiz
Sep 21 2018 04:28
sorry I don't understeand :/
what is wrong and right?
@DYLANFREE
黄俊
@DYLANFREE
Sep 21 2018 04:30
wait a minute
Chinese input is Full-width symbol,“”this is wrong,so it didn't work.
黄俊
@DYLANFREE
Sep 21 2018 04:39
""""""" “”“”“”“”
they are different.Missing quate is not the main problem,i guess Codepen autocompletes this small mistake for me.
(forgive my poor English,i have not used English for a long time)
@Marmiz
Claudio Restifo
@Marmiz
Sep 21 2018 04:41

@DYLANFREE no need to apologise, overcoming language barrier can be difficult, you are doing great :clap: :sparkles:


By the look of it yes, you were typing in a "wrong" type of quote. That means that the browser won't read them correctly.
Is it working now your link?

黄俊
@DYLANFREE
Sep 21 2018 04:43
yes,it work└(^o^)┘
Claudio Restifo
@Marmiz
Sep 21 2018 04:44
:sparkles: :sparkles: :sparkles:
psyperl
@psyperl
Sep 21 2018 06:17
ok so i have small weekend window.. should i learn async await.. or will it takes too heavy to understand
Aditya
@ezioda004
Sep 21 2018 07:09
Just an article or two about the whole thing should do it
psyperl
@psyperl
Sep 21 2018 07:09
oo ok, will try
psyperl
@psyperl
Sep 21 2018 07:25
to my understanding ( which often wrong ) that seems to changed the promise chain back to imperial style ? i might skip async and await for now :smile:
imperial? lol i meant imperative
Aditya
@ezioda004
Sep 21 2018 07:40
Yeah more procedural/sequential but its very much declarative if you think about it. Example: you tell the function to wait until some task is completed but you dont tell it how exactly it should wait, it automatically does it for you
psyperl
@psyperl
Sep 21 2018 07:42
yeah
it does not anything new from Promise chain
i haven't found a use case for it yet
psyperl
@psyperl
Sep 21 2018 07:48
ok i think i found a use case for it :smile:
and yeah it can be useful
Kelechi Chinaka
@ke1echi
Sep 21 2018 09:58
Array.prototype.filter = function(callback){
  console.log(this)
  var newArray = [];
  for (let i = 0, len = this.length; i < len; i++) {
    if (this[i] > 3) newArray.push(this[i]);
  }
  return newArray;
};
this my code
May Kittens Devour Your Soul
@diomed
Sep 21 2018 09:59
psyperl
@psyperl
Sep 21 2018 10:12
lol
Kelechi Chinaka
@ke1echi
Sep 21 2018 10:24
nvm..done
Otter
@lambomiura
Sep 21 2018 12:05
Hey how could I secure api for chrome extension - do need to use https or http is enough, and how about some "key" so only extension users can talk to API ? API is just returning one json file, that's all
Kyle Holm
@thekholm80
Sep 21 2018 16:32
good morning, /help
Christopher McCormack
@cmccormack
Sep 21 2018 16:34
@thekholm80 heya
Kyle Holm
@thekholm80
Sep 21 2018 16:34
@cmccormack is your state on fire?
i know mine is
Christopher McCormack
@cmccormack
Sep 21 2018 16:35
@thekholm80 probably
always fires up north
but I don't really read the news
Kyle Holm
@thekholm80
Sep 21 2018 16:35
every time i leave my house it smells like campfire outside
good times
Christopher McCormack
@cmccormack
Sep 21 2018 16:36
grab your marshmallows and run away! use them as quick calories while you drive away from the smoke
Kyle Holm
@thekholm80
Sep 21 2018 16:36
lol
psyperl
@psyperl
Sep 21 2018 16:38
i decided not to use && and || for ternary replacement
i am gonna line up both code and you guys might see my strong reason not to
e && 1 || 2
e ? 1 : 0
Christopher McCormack
@cmccormack
Sep 21 2018 16:40
@psyperl strong reason?
psyperl
@psyperl
Sep 21 2018 16:40
yeah
Christopher McCormack
@cmccormack
Sep 21 2018 16:40
what's the strong reason?
psyperl
@psyperl
Sep 21 2018 16:40
it adds 2 extra characters
Aditya
@ezioda004
Sep 21 2018 16:41
Thats the strongest reason there could be
Christopher McCormack
@cmccormack
Sep 21 2018 16:41
what's the strong reason?
psyperl
@psyperl
Sep 21 2018 16:41
that was it
you could loose in code golf with 2 extra chars
better to avoid it
Kyle Holm
@thekholm80
Sep 21 2018 16:42
preach
Christopher McCormack
@cmccormack
Sep 21 2018 16:42
Who was suggesting to replace conditional operator?
Aditya
@ezioda004
Sep 21 2018 16:42
Golf code :heavy_check_mark:
Readability :heavy_multiplication_x:
psyperl
@psyperl
Sep 21 2018 16:42
^
Christopher McCormack
@cmccormack
Sep 21 2018 16:43
caret?
Niraj Nandish
@Nirajn2311
Sep 21 2018 16:43
@diomed i'm ready for your css worries :cat:
psyperl
@psyperl
Sep 21 2018 16:43
no one one suggesting the replacement.. but i was attempting to
Christopher McCormack
@cmccormack
Sep 21 2018 16:43
ternary is much easier to read imo
just neat that you can replace it
psyperl
@psyperl
Sep 21 2018 16:44
i like shorter code for some reason... easier to read
readability != understandability
Christopher McCormack
@cmccormack
Sep 21 2018 16:45
golf code is usually not very readable
psyperl
@psyperl
Sep 21 2018 16:45
it's only because they removed spaces
Christopher McCormack
@cmccormack
Sep 21 2018 16:45
sure a ternary may be, but some of the other stuff that's done adds a mental tax
not only that at all
psyperl
@psyperl
Sep 21 2018 16:46
yeah
Christopher McCormack
@cmccormack
Sep 21 2018 16:46
maintaining all the tricks in your head while reviewing can make it really difficult
Aditya
@ezioda004
Sep 21 2018 16:46
Also a pain to debug
Christopher McCormack
@cmccormack
Sep 21 2018 16:47
terse understandable code is fine
psyperl
@psyperl
Sep 21 2018 16:47
my new method is using Promise for most things.. very readable .. but so verbose
Christopher McCormack
@cmccormack
Sep 21 2018 16:47
can be better even, map is easier to follow than a for loop and leads to less side-effects, for instance
Aditya
@ezioda004
Sep 21 2018 16:47
@psyperl Even for synchronous code?
psyperl
@psyperl
Sep 21 2018 16:48
yeah lol
been a while since i don't have to think to code
Aditya
@ezioda004
Sep 21 2018 16:48
You really like the new toy
psyperl
@psyperl
Sep 21 2018 16:48
hehe yeah... it's like a pattern i am expecting to automate it one day
like lego.. easy to atttach detach
except the part i don't know how to return it on rgb challenge
Christopher McCormack
@cmccormack
Sep 21 2018 16:50
Promises can make things more difficult, you're trying to work in a callback so you may have scoping issues
if you try to apply it to everything it's going to be a pain
psyperl
@psyperl
Sep 21 2018 16:51
i wonder why i didn't feel the pain .. maybe i haven't met some case that makes it difficult?
Aditya
@ezioda004
Sep 21 2018 16:51
@psyperl I could be wrong but I see that you're using promises just for chaining?
psyperl
@psyperl
Sep 21 2018 16:51
@ezioda004 yes
and error handling
so each statement is secure..
i didn't show the handling on the rgb case though
except on rgb case that's purely chaining
Aditya
@ezioda004
Sep 21 2018 16:53
You could just curry the regular functions instead
May Kittens Devour Your Soul
@diomed
Sep 21 2018 16:53
where is that css wizard all day I wonder?
psyperl
@psyperl
Sep 21 2018 16:53
i don't understand curry
diomed @diomed shrugs his head and looks around for @Nirajn2311
May Kittens Devour Your Soul
@diomed
Sep 21 2018 16:54
@ezioda004 to make them more spicy, right? ;)
Aditya
@ezioda004
Sep 21 2018 16:54
@psyperl A good article to get started
psyperl
@psyperl
Sep 21 2018 16:54
i like to have a chance to reuse the portion in aynchronous way when needed
aww i don't like it @ezioda004 lol
Niraj Nandish
@Nirajn2311
Sep 21 2018 16:55
The css wizard is now ready for @diomed
psyperl
@psyperl
Sep 21 2018 16:56
Promise is much easier to read i think
May Kittens Devour Your Soul
@diomed
Sep 21 2018 16:56
psyperl
@psyperl
Sep 21 2018 16:57
i don't think @cmccormack seen the code i posted
Christopher McCormack
@cmccormack
Sep 21 2018 16:57
@psyperl nope I'm not some kind of wizard
May Kittens Devour Your Soul
@diomed
Sep 21 2018 16:57
@cmccormack ha! lies , all lies.
Aditya
@ezioda004
Sep 21 2018 16:58
@psyperl Hmm, or perhaps you can imitate the chaining:
const obj = {
  meth1(){
    //do stuff
   return this;
  },
  meth2(){
  //do stuff
  return this;
  }
}
obj.meth1().meth2();
psyperl
@psyperl
Sep 21 2018 16:58
let me know if it's easy to read.. more critics the better.. because this is entirely experimental for me
Aditya
@ezioda004
Sep 21 2018 16:58
I think using Promise for synchronous code is a bit overkill
Kyle Holm
@thekholm80
Sep 21 2018 16:58
meth isn't cool guys
psyperl
@psyperl
Sep 21 2018 16:58
const promise_toHaveHexInUpperCase = hex =>
  new Promise((kept, broken) => toHaveHexInUpperCase(kept,broken, hex))
const toHaveHexInUpperCase = (kept, broken, hex) =>
  kept(hex.map(e => e.toUpperCase() ))

const promise_toConvertNumberToHex = rgb =>
  new Promise((kept, broken) => toConvertNumberToHex(kept,broken, rgb))
const toConvertNumberToHex = (kept, broken, rgb) =>
  kept(rgb.map(e => e.toString(16)))

const promise_toHaveNumberInRange = rgb =>
  new Promise((kept, broken) => toHaveNumberInRange(kept,broken, rgb))
const toHaveNumberInRange = (kept, broken, rgb) =>
  kept(rgb.map(e => e < 0 ? 0 : e > 255 ? 255 : e))

const promise_toHaveZeroPadding = hex =>
  new Promise((kept, broken) => toHaveZeroPadding(kept,broken, hex))
const toHaveZeroPadding = (kept,broken, hex) =>
  kept(hex.map(e => e.length === 1 ? `0${e}` : e))

const promise_toFlattenTheArray = hex =>
  new Promise((kept, broken) => toFlattenTheArray(kept,broken, hex))
const toFlattenTheArray = (kept,broken, hex) =>
  kept(hex.reduce((b,v) => b + v))

const rgb = (r,g,b) =>
  promise_toHaveNumberInRange([r,g,b])
  .then(promise_toConvertNumberToHex)
  .then(promise_toHaveHexInUpperCase)
  .then(promise_toHaveZeroPadding)
  .then(promise_toFlattenTheArray)
  .then(console.log, console.error)
May Kittens Devour Your Soul
@diomed
Sep 21 2018 16:58
meth isn't cool guys
psyperl
@psyperl
Sep 21 2018 16:58
i would like to see the curry version for that if i may @ezioda004
coa i think that is very easy for me to read and understand
also a chance to reuse and make it async
Christopher McCormack
@cmccormack
Sep 21 2018 17:00
yeah you could easily do this with currying
without the need for the actual Promise object
psyperl
@psyperl
Sep 21 2018 17:01
oo
Christopher McCormack
@cmccormack
Sep 21 2018 17:01
you could probably replace new Promise((kept, broken) => with just kept =>
hmm
psyperl
@psyperl
Sep 21 2018 17:01
yeah .. but in normal case usually perform verification
so broken is often exists
also some requires extra param
Christopher McCormack
@cmccormack
Sep 21 2018 17:03
well if you like it keep using it :)
psyperl
@psyperl
Sep 21 2018 17:03
yeah maybe soon i will find a flaw on the pattern
like you said about context... i am having trouble returning the value of the operation to the caller of rgb function
Christopher McCormack
@cmccormack
Sep 21 2018 17:04
do you have examples using broken?
psyperl
@psyperl
Sep 21 2018 17:04
yeah
but in picture is that ok?
Christopher McCormack
@cmccormack
Sep 21 2018 17:04
eh
don't need it just seeing if you're using it :)
May Kittens Devour Your Soul
@diomed
Sep 21 2018 17:05
no, Pepsi isn't ok
psyperl
@psyperl
Sep 21 2018 17:05
Screen Shot 2018-09-20 at 21.18.50.png
i am using it .. yeah.. mostly network fetch etc
the rgb was an extreme example hehehe
being different is fine.. reason i ask around usually to see if i made some mistake
like shouldn't do this might cause something something etc
Niraj Nandish
@Nirajn2311
Sep 21 2018 17:08
@diomed the css guy is waiting
May Kittens Devour Your Soul
@diomed
Sep 21 2018 17:10
@Nirajn2311 lol, I gave you instructions in private, the other day
Christopher McCormack
@cmccormack
Sep 21 2018 17:10
@psyperl might want to move your non-promise functions above the promise function so if you refactor they won't be out of scope, they aren't hoisted like function statements
psyperl
@psyperl
Sep 21 2018 17:14
hmm that's a bit difficult to digest
Niraj Nandish
@Nirajn2311
Sep 21 2018 17:14
@diomed I still didnt get what you are trying to do
psyperl
@psyperl
Sep 21 2018 17:15
but i do realize they are on their own scope
May Kittens Devour Your Soul
@diomed
Sep 21 2018 17:15
lile, just flip it . mirror it @Nirajn2311
Niraj Nandish
@Nirajn2311
Sep 21 2018 17:15
It doesnt look good if you do it
May Kittens Devour Your Soul
@diomed
Sep 21 2018 17:16
no, huh? hhmmm
Niraj Nandish
@Nirajn2311
Sep 21 2018 17:16
Ask your question here and we'll see what everyone thinks of it
Better to have more opinions
psyperl @psyperl reading about hoisting
May Kittens Devour Your Soul
@diomed
Sep 21 2018 17:17
yes. u can hoist on digital ocean
psyperl
@psyperl
Sep 21 2018 17:17
:smile:
@cmccormack ah yeah.. i never rely on hoisting though .. that's weird concept.. always often to declare first most of the things i use
Christopher McCormack
@cmccormack
Sep 21 2018 17:20
that's what I'm suggesting
psyperl
@psyperl
Sep 21 2018 17:20
yes
ic yeah to make them stay in scope as in known/declared ..
Christopher McCormack
@cmccormack
Sep 21 2018 17:22
right
psyperl
@psyperl
Sep 21 2018 17:23
maybe @ezioda004 is right.. maybe i like Promise too much .. but that's probably because it's new to me
Christopher McCormack
@cmccormack
Sep 21 2018 17:23
@psyperl probably the best way to learn all about it, learn it's strengths and weaknesses
May Kittens Devour Your Soul
@diomed
Sep 21 2018 17:23
looks promissing
psyperl
@psyperl
Sep 21 2018 17:24
yeah i am trying to put the code in practice.. so i get used to their characteristics better
and the catch at the end is really really nice
@diomed no noobmissing?
Christopher McCormack
@cmccormack
Sep 21 2018 17:27
@psyperl I did the same with async/await, playing with it as much as I could to find issues
fetch as well
psyperl
@psyperl
Sep 21 2018 17:28
i am having difficulty with async and await for some reason :(
Aditya
@ezioda004
Sep 21 2018 17:29
@psyperl Since with promise you can only interact with values in .then(), you could have a global variable, have the last then() assign value to the variable
psyperl
@psyperl
Sep 21 2018 17:29
// calling test never gave me the correct result.. instead got promise object
const test = async() => await somePromise()
@ezioda004 tried that too but it returned to fast when i attempt to return the globals
Christopher McCormack
@cmccormack
Sep 21 2018 17:31
@psyperl I think you would just return somePromise() in that example
psyperl
@psyperl
Sep 21 2018 17:31
let theGlob
const useGlobals = _ => {
  somePromise().then( x => theGlob = x )
  return useGlobals
}
somehow that often fails too
Christopher McCormack
@cmccormack
Sep 21 2018 17:31
but the real power of async/await is doing work within the async function, not returning a promise immediatly
psyperl
@psyperl
Sep 21 2018 17:32
@cmccormack seems like what Promise.all can do?
Christopher McCormack
@cmccormack
Sep 21 2018 17:32
you get access to the resolve data as if it were just a synchronous call
no
you still need Promise.all with async await if you need parallel work to be done
but you don't need .then within an async function
psyperl
@psyperl
Sep 21 2018 17:33
you meant pull out the context and work with the value inside the then context outside?
Christopher McCormack
@cmccormack
Sep 21 2018 17:34
@psyperl basically
psyperl
@psyperl
Sep 21 2018 17:34
i usually push the values to another Promise to process hehehe... since i haven't played with async await yet
Christopher McCormack
@cmccormack
Sep 21 2018 17:35
you may want to look at composition as well if you haven't
psyperl
@psyperl
Sep 21 2018 17:35
composition?
no i don't that's what you trying to refer
Christopher McCormack
@cmccormack
Sep 21 2018 17:37
nope just a functional programming concept
it's a good way to perform work against a unit of data
seems like what you're trying to do above
psyperl
@psyperl
Sep 21 2018 17:39
ah i think i made similar function to put function calls into an array and execute it in one of fcc challenge
Christopher McCormack
@cmccormack
Sep 21 2018 17:39
but I'm not sure how it handles errors
psyperl
@psyperl
Sep 21 2018 17:39
right .. errors handling is important that's how i like Promises
i leave out during first pass (on coding) .. then when i know how to handle it i can easily put it in
catch at the end filtering the type of error i need to handle
because it breaks the chain when it rejected/broken once right?
Christopher McCormack
@cmccormack
Sep 21 2018 17:41
with async await you may be able to wrap your composition in a try/catch and just throw the error if it fails
correct, the .then should never be invoked if it fails
psyperl
@psyperl
Sep 21 2018 17:43
yeah one part i like about the chaining then because i can get away from try catch actually
not getting away from error handling concept.. just the code structure
Christopher McCormack
@cmccormack
Sep 21 2018 17:43
I think try catch makes it more readable when using async/await but it's up to you and what you're doing
psyperl
@psyperl
Sep 21 2018 17:44
about async await i think there is one case i couldn't do ( optimally ) with chaining then
at least right now i have no idea how to handle it is like...
Christopher McCormack
@cmccormack
Sep 21 2018 17:45
@psyperl found an article I remember reading that I thought you might like https://hackernoon.com/6-reasons-why-javascripts-async-await-blows-promises-away-tutorial-c7ec10518dd9
psyperl
@psyperl
Sep 21 2018 17:46
someProcess()
  .then(SomeHeavyProcessA)
  .then(SomeProcessthatNeedHeavyProcessA)
  .then(SomeProcessNeedTheAboveResult)
  .then(SomeProcessNeedHeaveyProcessA) <-- failing here i need to recall somehaveyprocessA again .. might need to save the result somewhere
psyperl @psyperl reading the article
psyperl
@psyperl
Sep 21 2018 17:49
lol that is a bit silly @cmccormack
Any async function returns a promise implicitly, and the resolve value of the promise will be whatever you return from the function (which is the string "done" in our case).
problem is .. he is returning something that has nothing to do with the async lol
Christopher McCormack
@cmccormack
Sep 21 2018 17:51
he is returning a promise
how is that not related?
psyperl
@psyperl
Sep 21 2018 17:52
he is returning static string "done"
Christopher McCormack
@cmccormack
Sep 21 2018 17:52
nope
Any async function returns a promise implicitly
@cmccormack yes that's what i am expected but i can't do ..
Christopher McCormack
@cmccormack
Sep 21 2018 17:53
keep reading
psyperl
@psyperl
Sep 21 2018 17:53
ok
psyperl @psyperl keep reading
Christopher McCormack
@cmccormack
Sep 21 2018 17:53
// this will not work in top level
// await makeRequest()

// this will work
makeRequest().then((result) => {
  // do something
})
so in //do something you can log result and it should be 'done'
psyperl
@psyperl
Sep 21 2018 17:54
that's how i understand it yes
Christopher McCormack
@cmccormack
Sep 21 2018 17:55
well it's a promise, so 'done' won't be logged until the await getJSON completes and the async function returns the Promise
psyperl
@psyperl
Sep 21 2018 17:57
2. Error handling.. that was my question yesterday .. he did it wrong
const makeRequest = () => {
  try {
    getJSON()
      .then(result => {
        // this parse may fail
        const data = JSON.parse(result)
        console.log(data)
      })
      // uncomment this block to handle asynchronous errors
      // .catch((err) => {
      //   console.log(err)
      // })
  } catch (err) {
    console.log(err)
  }
}
this one
JSON.parse(result) should be in a promise to keep it in context
Ezioda solved this case yesterday hehehe
Christopher McCormack
@cmccormack
Sep 21 2018 17:59
not sure I'm following
psyperl
@psyperl
Sep 21 2018 18:02
const promiseToParseJSON
const makeRequest = () => 
  getJSON()
    .then(result => JSON.parse(result) )
    .then(console.log)
    .catch( e => // anything thrown both should be handled here)
Christopher McCormack
@cmccormack
Sep 21 2018 18:02
hmm yeah I see that now
psyperl
@psyperl
Sep 21 2018 18:05
yeah i think is the number 4. intermediate value .. that can be problem without async / await .. that's similar problem i pointed on :point_up: September 22, 2018 12:46 AM
Christopher McCormack
@cmccormack
Sep 21 2018 18:06
it looks like it does catch it when you uncomment https://codepen.io/cmccormack/pen/RYdePO?editors=1010
psyperl
@psyperl
Sep 21 2018 18:06
and i can't say much about point 6. Debugging .. sometimes i found a way for the debugger to stop .. but sometimes not .. a bit weird
nope
Christopher McCormack
@cmccormack
Sep 21 2018 18:08
yup
look at the console
comment it back out
see how it's uncaught
then uncomment it
psyperl
@psyperl
Sep 21 2018 18:09
ah lol
Christopher McCormack
@cmccormack
Sep 21 2018 18:10
I didn't actually know it could do that, pretty cool
Aditya
@ezioda004
Sep 21 2018 18:10
@psyperl Some good ol' chaining on regular object
const rgb = (r, g, b) => {
  let rgb = [r,g,b];
  return {
    toHaveNumberInRange(){
      rgb = rgb.map(e => e < 0 ? 0 : e > 255 ? 255 : e);
      return this;
    },
    toConvertNumberToHex(){
      rgb = rgb.map(e => e.toString(16))
      return this;
    },
    toHaveHexInUpperCase(){
      rgb = rgb.map(e => e.toUpperCase());
      return this;
    },
    toHaveZeroPadding(){
      rgb = rgb.map(e => e.length === 1 ? `0${e}` : e)
      return this;
    },
    toFlattenTheArray(){
      return rgb.reduce((b,v) => b + v);
    }
  }
}
rgb(255, 255, 255).toHaveNumberInRange().toConvertNumberToHex().toHaveHexInUpperCase().toHaveNumberInRange().toHaveZeroPadding().toFlattenTheArray();
psyperl
@psyperl
Sep 21 2018 18:10
@cmccormack is funny how he use try on Promise though .. we can't use .catch
Christopher McCormack
@cmccormack
Sep 21 2018 18:10
@ezioda004 now show us some composition!
psyperl
@psyperl
Sep 21 2018 18:11
@ezioda004 hang on let me read
Christopher McCormack
@cmccormack
Sep 21 2018 18:12
@psyperl he did that to show an example
psyperl
@psyperl
Sep 21 2018 18:12
@ezioda004 yeah that would work .. but not sure how to refactor that and how to handle error, thanks for showing me currying
yes
Aditya
@ezioda004
Sep 21 2018 18:12
For composition you'd have to declare the function like outside the object
Christopher McCormack
@cmccormack
Sep 21 2018 18:13
that may be an old example though, I think it might function slightly different now
Aditya
@ezioda004
Sep 21 2018 18:13
Hmm error handling could be added
psyperl
@psyperl
Sep 21 2018 18:14

i would like this

rgb(255, 255, 255)
  .toHaveNumberInRange()
  .toConvertNumberToHex()
  .toHaveHexInUpperCase()
  .toHaveNumberInRange()
  .toHaveZeroPadding()
  .toFlattenTheArray()

but not sure i would like that one inside the implementation

Aditya
@ezioda004
Sep 21 2018 18:15
Isnt that same as example?
psyperl
@psyperl
Sep 21 2018 18:15
and would also be cool if i could use another function with similar path
otherFunction()
  .toHaveNumberInRange()
  .toConvertNumberToHex()
  .toHaveHexInUpperCase()
  .toHaveNumberInRange()
  .toHaveZeroPadding()
  .toFlattenTheArray()
@ezioda004 which example?
yeah that's from your example
Aditya
@ezioda004
Sep 21 2018 18:16
Thats doable, you could have that object in in the prototype chain
psyperl
@psyperl
Sep 21 2018 18:16
ahh so this is like declaring a method on an anonymous object that you return from the function?
Aditya
@ezioda004
Sep 21 2018 18:17
Yeah, rgb variable is in closure
psyperl
@psyperl
Sep 21 2018 18:17
bascially you are returning an anonymous object that contains all the required method to solve the problem
Aditya
@ezioda004
Sep 21 2018 18:18
I wont say class, just an object :P
psyperl
@psyperl
Sep 21 2018 18:18
correct object
Aditya
@ezioda004
Sep 21 2018 18:18
Basically yeah
psyperl
@psyperl
Sep 21 2018 18:19
nice trick.. but i still prefer Promise hehehe
Aditya
@ezioda004
Sep 21 2018 18:20
That was me when I fully learned .reduce()
I'd use that everywhere
psyperl
@psyperl
Sep 21 2018 18:21
hehehe
yeah this Promise is so new to me .. i get all excited about it
it helps me not to use curly braces .. that's one of the strong reason why :smile:
it saves two characters!
Aditya
@ezioda004
Sep 21 2018 18:24
Save 2 character here, burn 2 characters with tab, it evens out for me :D
psyperl
@psyperl
Sep 21 2018 18:24
lol
psyperl
@psyperl
Sep 21 2018 18:32
wow @cmccormack got away .. get him back!
Christopher McCormack
@cmccormack
Sep 21 2018 18:32
wha
psyperl
@psyperl
Sep 21 2018 18:44
funny how i know nothing about functional programming but most people that saw my code think i am doing it haha .. i was just trying to not use the braces
i think it's called braceless programming paradigm
psyperl
@psyperl
Sep 21 2018 18:49
still need braces for objects though

but i think

const x = 1: "one", 2: "two", 3: "three"

should be sufficient

Aditya
@ezioda004
Sep 21 2018 18:54
If only saying Alexa, make object 1 1, 2 2 , 3 3 would work
psyperl
@psyperl
Sep 21 2018 18:55
you are doing alexa challenge ?
Aditya
@ezioda004
Sep 21 2018 18:55
Whats that?
Aditya
@ezioda004
Sep 21 2018 18:58
Thats nice, good for quizzes and stuff but not very dynamic
psyperl
@psyperl
Sep 21 2018 18:58
i don't have echo so
but i can use SiriKit
now that's my next challenge.. i need to adopt the promise style flow structure with grand central dispatch in Swift
psyperl
@psyperl
Sep 21 2018 19:04
knowing Promise will revive one of my proj that has been sleeping for so long :smile:
it's the kind of code where you sit down.. looking at the code and fell asleep immediately haha
one don't need bed time stories for kid .. give them code!
May Kittens Devour Your Soul
@diomed
Sep 21 2018 21:34
@ezioda004 u here , mby?