software-tools-books / js4ds

JavaScript for Data Science
https://third-bit.com/js4ds/
Other
187 stars 32 forks source link

suggestion: additional info on .map() syntax #201

Open mfoos opened 4 years ago

mfoos commented 4 years ago

Manipulating Page -> Bibliographic Citations

Hey folks,

I have to compliment you on the skimability of this book (even if that's a dubious compliment), because I personally need a big-picture before I can go into details. Also forgive me if I missed this info skimming, but I don't think I did because I did a ctrl+F for "map".

Here are the two things I found confusing:

1) Inconsistent use of parens: map is introduced with data.map((x) => { return x.slice(0, 2) }) but in later examples, the anonymous parameter (?) is used without parens.: link.textContent.split(',').map(s => s.trim())

2) The curly braces inside the parameter parens:

.map(({node, text}) => (
      {node,
       text: text.map(cite => `<a href="../bib/#${cite}">${cite}</a>`)}
    ))

I also want to note that while I believe in the ol "learn yourself by googling", this was not terribly fruitful for me because of the multiple versions of syntax available in docs around the interwebs (see: https://stackoverflow.com/questions/4146984/curly-braces-inside-javascript-parameters-for-functions

Thanks! Awesome resource!