These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Dec 2018
Jason Luboff
@JLuboff
Dec 27 2018 00:00
const allControlIDs = steps
        .map(({ hazardAndControls }) =>
          hazardAndControls.map(({ controlIDs }) => controlIDs)
        )
        .reduce((acc, cur) => acc.concat(cur), [])
        .reduce((acc, cur) => acc.concat(cur), []);
two maps... two reduce...
Brad
@bradtaniguchi
Dec 27 2018 00:01
whoa >.>
Jason Luboff
@JLuboff
Dec 27 2018 00:01
Told you haha
I know there must be a way to clean that up...
Brad
@bradtaniguchi
Dec 27 2018 00:02
So hold on, the data is:
steps: [
  {
    hazardAndControls: [
      {
         controlID: ['id'] // got lazy to indent format this
      }
    ]
  }
]
Jason Luboff
@JLuboff
Dec 27 2018 00:03
controlIDs is just an array of numbers
Brad
@bradtaniguchi
Dec 27 2018 00:03
I edited, like that right?
Jason Luboff
@JLuboff
Dec 27 2018 00:03
Ya
And so we will have an unknown number of steps and an unknown number of hazardAndControls
Brad
@bradtaniguchi
Dec 27 2018 00:04
I see, so it looks like you could more or less do it with 3 "loops", in some way or form.
Jason Luboff
@JLuboff
Dec 27 2018 00:04
Ya...I was thinking I have one too many here
Brad
@bradtaniguchi
Dec 27 2018 00:05
The thing with "chaining" reduce,filter,forEach is you iterate over the array again and again, which might add extra work
actually It will add extra work haha
Jason Luboff
@JLuboff
Dec 27 2018 00:06
Absolutely
Brad
@bradtaniguchi
Dec 27 2018 00:06
Regardless tho, we gotta clean up dah code
Jason Luboff
@JLuboff
Dec 27 2018 00:07
I agree
Brad
@bradtaniguchi
Dec 27 2018 00:08
Let me write it down on vscode real quick
Jason Luboff
@JLuboff
Dec 27 2018 00:11
Mmmk...I'm still looking at this to see if I can get anything better too
Brad
@bradtaniguchi
Dec 27 2018 00:15
This is what I got, idk about it being valid JS, since my linter is to strict on where I wrote it so I had a bunch of errors (like shadow variable names), but you should get the idea:
const allControlIDs = steps.reduce((allControlIds, steps) => {
  const hazardsAndControls = steps.hazardAndControls.reduce((hazardsAndControls, hazardAndControl) => {
    hazardsAndControls.push(...hazardAndControl.controlIDs);
    return hazardsAndControls;
  }, []);
  allControlIds.push(...hazardsAndControls);
  return arrControlIds;
}, []);
Jason Luboff
@JLuboff
Dec 27 2018 00:15
Lets see here
Brad
@bradtaniguchi
Dec 27 2018 00:16
Definantly the sorta function/code you test :P
Jason Luboff
@JLuboff
Dec 27 2018 00:16
It works after I changed arrControlIds to allControlIds
Brad
@bradtaniguchi
Dec 27 2018 00:16
Haha alright cool, yea might of been a typo
heck if this pattern is common you could totally write a helper higher level method that takes in the nested array properties you want to "flatten"
Jason Luboff
@JLuboff
Dec 27 2018 00:17
It might be.. I haven't worked a ton on the backend code for this yet
Brad
@bradtaniguchi
Dec 27 2018 00:19
I'd think about it, from what I understand from this app I remember the data having a good amount of levels. Might not be worth the work, you could easily refactor this into seperate functions that are used together, and are re-usable.
Jason Luboff
@JLuboff
Dec 27 2018 00:19
Ya there's a bit of nesting in the data structure heh
Brad
@bradtaniguchi
Dec 27 2018 00:21
I think this code isn't as performat as could be either, 1 reduce at the top level and nested forEaches might be faster, but it all depends spread operator performance. But I degress
Jason Luboff
@JLuboff
Dec 27 2018 00:24
So...just to make sure I fully understand whats happening here. The inner reduce is flattening the controlid array for each step, and the outer reduce is then flattening each steps flattened array
Brad
@bradtaniguchi
Dec 27 2018 00:28
Yes pretty much
Jason Luboff
@JLuboff
Dec 27 2018 00:29
Thanks man.. you made my ugly code prettier.. lol
Brad
@bradtaniguchi
Dec 27 2018 00:30
np :D
Jason Luboff
@JLuboff
Dec 27 2018 00:31
And I'm slowly learning more about how to use reduce outside of arithemtic (jesus christ spelling?)
Brad
@bradtaniguchi
Dec 27 2018 00:33
Just remember its "syntax sugar" to this sorta code:
let someVar
someArr.forEach(() => {
  // doing something to somVar over an array
});
where forEach can be any loop
Jason Luboff
@JLuboff
Dec 27 2018 00:35
True
Brad
@bradtaniguchi
Dec 27 2018 00:39
I gotta hit up the bank real quick, so C ya in a week @JLuboff :D
Jason Luboff
@JLuboff
Dec 27 2018 00:41
Alright man, have a good one
BP
@bgq007
Dec 27 2018 14:11
There really isn’t a general FCC chat on here. Would anyone be opposed to me asking a question unrelated to FCC ….
Aditya
@ezioda004
Dec 27 2018 14:18
@bgq007 As long as it doesnt violate FCC's COC you can ask
BP
@bgq007
Dec 27 2018 14:24
@ezioda004 I can’t imagine it does, I have been trying to switch from Google products. Im now using FireFox Quantum, but I do have Gmail accounts. I use DuckDuckGo for my search, but if you have GMAIL logged in (which I pretty much do all the time) Google still ‘sees' (from my understanding)…. with addition, I don’t really like DuckDuckGo. Id prefer to use Google search without being signed in. But can’t if logged into Gmail. Anyway, point is, anyone know of WEB based email services with IMAP so I can import all my different account into one place? Just like I could with Mail (Apple Mac OSX app)? I don’t want emails being stored locally. I want a web based solution. I just ran across Protonmail so I am checking them out. But wanted to get opinions from others. Small fee would be fine, but need to be able to access / import Gmail, Outlook and personal domain accounts. One place, all my emails. Thanks!
Jason Luboff
@JLuboff
Dec 27 2018 16:06
Morning :wave:
enestatli
@enestatli
Dec 27 2018 16:12
hello
:wave:
Jason Luboff
@JLuboff
Dec 27 2018 16:13
How's it going?
enestatli
@enestatli
Dec 27 2018 16:21
fine got stuck JS again, you?
Jason Luboff
@JLuboff
Dec 27 2018 16:22
Learning Scheme right now
enestatli
@enestatli
Dec 27 2018 16:23
new language?
whats it?
Jason Luboff
@JLuboff
Dec 27 2018 16:24
Its MIT's version of LISP. Only learning as its the language used for the book Structure and Interpretation of Computer Programs
Which I'm going through that book to help establish a better understanding of core principles
enestatli
@enestatli
Dec 27 2018 16:30
just googled what LIPS is and shoked
it is invented around 1958
Jason Luboff
@JLuboff
Dec 27 2018 16:30
Yup. It's an old language hah
enestatli
@enestatli
Dec 27 2018 16:31
and it still uses
wow
Jason Luboff
@JLuboff
Dec 27 2018 16:32
Ya, so the book uses the 'dialect' Scheme which is basically an evolved version of LISP
enestatli
@enestatli
Dec 27 2018 16:34
dialect as a term in programming language, huh :D
Jason Luboff
@JLuboff
Dec 27 2018 16:34
Apparently hah
BP
@bgq007
Dec 27 2018 16:46
Anyone know if you can access (edit) a SVG file from an external JS? What I mean is, I know I can target and change an SVG if its inline HTML. But depending on the file, that could be a ton of code. So, I’d like to be able to link to the SVG files via IMG or OBJECT or something like that but then still be able to target the SVG elements (like stroke color for example) from my JS file. I don’t think it’s possible, but thought Id ask. Would be really nice to keep the HTML clean.
Ankur sharma
@ankur1163
Dec 27 2018 17:13
I am also working with svg right now
@bgq007
I am working in react
if you know react, may be this will give you some pointers
BP
@bgq007
Dec 27 2018 17:14
@ankur1163 Im just starting to learn react, I could see that being useful, buts really confusing to me right now. I just used vanilla JS.
thanks for the link. Maybe I can use this desire to simply my HTML to learn react.
Christopher McCormack
@cmccormack
Dec 27 2018 19:12
:wave:
@JLuboff what's up
Jason Luboff
@JLuboff
Dec 27 2018 19:19
@cmccormack Hey man, whats happening?
Christopher McCormack
@cmccormack
Dec 27 2018 19:20
@JLuboff nm man working some FCC Pull Requests
How was your holiday?
Jason Luboff
@JLuboff
Dec 27 2018 19:21
Not too bad...nothing too exciting but no complaints there heh.. You?
Christopher McCormack
@cmccormack
Dec 27 2018 19:22
heh mine was good, still doing stuff which is fun. had another thing last night, should have one tomorrow, then another sunday
Jason Luboff
@JLuboff
Dec 27 2018 19:23
Jeez
Thats a lot
Christopher McCormack
@cmccormack
Dec 27 2018 19:23
started up a new app as well, personal one
Jason Luboff
@JLuboff
Dec 27 2018 19:23
Nice, what're you building?
Christopher McCormack
@cmccormack
Dec 27 2018 19:23
yeah lots of family in town/coming in to town after christmas
a media tracker app, something that helps you track your owned media across platforms
want to build it slowly and add features over time
Jason Luboff
@JLuboff
Dec 27 2018 19:24
Neat
Christopher McCormack
@cmccormack
Dec 27 2018 19:24
doing anything for yourself this holiday?
Jason Luboff
@JLuboff
Dec 27 2018 19:27
Nah.. back at work lol. Took the kiddo to the zoo on christmas and a really cool playground
otherwise.. thats about it. Not sure about NY
Christopher McCormack
@cmccormack
Dec 27 2018 19:28
sleep by 10 I bet haha
Jason Luboff
@JLuboff
Dec 27 2018 19:29
...perhaps... :P
Do you typically go out on NYE?
Christopher McCormack
@cmccormack
Dec 27 2018 19:38
@JLuboff nah we usually try to have people over but then nobody shows because nobody wants to drink and drive so we have tons of extra food, which we consume a lot of while watching twilight zone the next day and getting sick
Jason Luboff
@JLuboff
Dec 27 2018 19:38
:joy:
Christopher McCormack
@cmccormack
Dec 27 2018 19:38
My brother will be staying out our house this year though so we may try to do something
Jason Luboff
@JLuboff
Dec 27 2018 19:41
Thats the spirit!
Christopher McCormack
@cmccormack
Dec 27 2018 19:45
yeah! well I'm going to jump off now and find some work to do on the house - ttyl!
Jason Luboff
@JLuboff
Dec 27 2018 19:45
sEE YA
Ankur sharma
@ankur1163
Dec 27 2018 19:52
someone help me in react?
I have ternary operator for start stop button
how can i apply some sort of animation on these buttons?
Pagnito
@Pagnito
Dec 27 2018 20:32
node "masterclass" ...."Congratulations, you have made it through the first section, lets go over the modules we have used, Command line options to set environment variable, the console, we have learned how we can console many diffierent useful error to the console to help us debug"
NOOOO SHIT, console, i never heard of that before
this was the biggest section of the course btw
"masterclass"
ehutchllew
@ehutchllew
Dec 27 2018 20:34
@ankur1163 Are you familiar with animations in general?
Ankur sharma
@ankur1163
Dec 27 2018 20:43
yeah
I have played with trasitions and transform properties
@ehutchllew
Jason Luboff
@JLuboff
Dec 27 2018 21:26
@Pagnito Sounds invigorating
Pagnito
@Pagnito
Dec 27 2018 21:28
yes, im full of life right now, the type of life that ends up behind up bars
@JLuboff
Jason Luboff
@JLuboff
Dec 27 2018 21:32
heh
It is important to know that stuff (nodejs isn't strictly a web server) but...it is pretty boring
Karma Drukpa
@coderkarma
Dec 27 2018 21:34
let favoriteMove = `{
  "title": "Black Panther",
  "director": "Ryan Coogler",
  "year": 2018,
  "imdb": 7.5
}`;

let favoriteMovie = JSON.parse(favoriteMove);
 console.log(favoriteMovie);
Hey folks, just wanted to convert json data into object but it is throwing me syntax error
Jason Luboff
@JLuboff
Dec 27 2018 21:37
You need to escape each line if you're going to do that (have the string on seperate lines)
Or just use `` instead of'`
Argh
Use a template string (backticks) instead of regular single/double quotes for around the entire object
Karma Drukpa
@coderkarma
Dec 27 2018 21:38
ok so I could do string literal for that
Jason Luboff
@JLuboff
Dec 27 2018 21:38
Ya
let favoriteMove = `{
  "title": "Black Panther",
  "director": "Ryan Coogler",
  "year": 2018,
  "imdb":7.5
}`;
Karma Drukpa
@coderkarma
Dec 27 2018 21:38
no $ sign
Jason Luboff
@JLuboff
Dec 27 2018 21:40
No, you only need $ when you're adding a variable inside. i.e
const word = 'potato';
console.log(`My favorite word is ${word}`)
Karma Drukpa
@coderkarma
Dec 27 2018 21:41
why that didn't work even using backtick ?
Jason Luboff
@JLuboff
Dec 27 2018 21:42
It does work.. what do you currently have?
Karma Drukpa
@coderkarma
Dec 27 2018 21:46
thanks, sorry i was looking in my console. I forgot to refresh
Jason Luboff
@JLuboff
Dec 27 2018 21:46
:D