These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Dec 2018
Jason Luboff
@JLuboff
Dec 27 2018 00:00 UTC
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 UTC
whoa >.>
Jason Luboff
@JLuboff
Dec 27 2018 00:01 UTC
Told you haha
I know there must be a way to clean that up...
Brad
@bradtaniguchi
Dec 27 2018 00:02 UTC
So hold on, the data is:
steps: [
  {
    hazardAndControls: [
      {
         controlID: ['id'] // got lazy to indent format this
      }
    ]
  }
]
Jason Luboff
@JLuboff
Dec 27 2018 00:03 UTC
controlIDs is just an array of numbers
Brad
@bradtaniguchi
Dec 27 2018 00:03 UTC
I edited, like that right?
Jason Luboff
@JLuboff
Dec 27 2018 00:03 UTC
Ya
And so we will have an unknown number of steps and an unknown number of hazardAndControls
Brad
@bradtaniguchi
Dec 27 2018 00:04 UTC
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 UTC
Ya...I was thinking I have one too many here
Brad
@bradtaniguchi
Dec 27 2018 00:05 UTC
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 UTC
Absolutely
Brad
@bradtaniguchi
Dec 27 2018 00:06 UTC
Regardless tho, we gotta clean up dah code
Jason Luboff
@JLuboff
Dec 27 2018 00:07 UTC
I agree
Brad
@bradtaniguchi
Dec 27 2018 00:08 UTC
Let me write it down on vscode real quick
Jason Luboff
@JLuboff
Dec 27 2018 00:11 UTC
Mmmk...I'm still looking at this to see if I can get anything better too
Brad
@bradtaniguchi
Dec 27 2018 00:15 UTC
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 UTC
Lets see here
Brad
@bradtaniguchi
Dec 27 2018 00:16 UTC
Definantly the sorta function/code you test :P
Jason Luboff
@JLuboff
Dec 27 2018 00:16 UTC
It works after I changed arrControlIds to allControlIds
Brad
@bradtaniguchi
Dec 27 2018 00:16 UTC
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 UTC
It might be.. I haven't worked a ton on the backend code for this yet
Brad
@bradtaniguchi
Dec 27 2018 00:19 UTC
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 UTC
Ya there's a bit of nesting in the data structure heh
Brad
@bradtaniguchi
Dec 27 2018 00:21 UTC
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 UTC
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 UTC
Yes pretty much
Jason Luboff
@JLuboff
Dec 27 2018 00:29 UTC
Thanks man.. you made my ugly code prettier.. lol
Brad
@bradtaniguchi
Dec 27 2018 00:30 UTC
np :D
Jason Luboff
@JLuboff
Dec 27 2018 00:31 UTC
And I'm slowly learning more about how to use reduce outside of arithemtic (jesus christ spelling?)
Brad
@bradtaniguchi
Dec 27 2018 00:33 UTC
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 UTC
True
Brad
@bradtaniguchi
Dec 27 2018 00:39 UTC
I gotta hit up the bank real quick, so C ya in a week @JLuboff :D
Jason Luboff
@JLuboff
Dec 27 2018 00:41 UTC
Alright man, have a good one
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 UTC
@bgq007 As long as it doesnt violate FCC's COC you can ask
@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 UTC
Morning :wave:
enestatli
@enestatli
Dec 27 2018 16:12 UTC
hello
:wave:
Jason Luboff
@JLuboff
Dec 27 2018 16:13 UTC
How's it going?
enestatli
@enestatli
Dec 27 2018 16:21 UTC
fine got stuck JS again, you?
Jason Luboff
@JLuboff
Dec 27 2018 16:22 UTC
Learning Scheme right now
enestatli
@enestatli
Dec 27 2018 16:23 UTC
new language?
whats it?
Jason Luboff
@JLuboff
Dec 27 2018 16:24 UTC
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 UTC
just googled what LIPS is and shoked
it is invented around 1958
Jason Luboff
@JLuboff
Dec 27 2018 16:30 UTC
Yup. It's an old language hah
enestatli
@enestatli
Dec 27 2018 16:31 UTC
and it still uses
wow
Jason Luboff
@JLuboff
Dec 27 2018 16:32 UTC
Ya, so the book uses the 'dialect' Scheme which is basically an evolved version of LISP
enestatli
@enestatli
Dec 27 2018 16:34 UTC
dialect as a term in programming language, huh :D
Jason Luboff
@JLuboff
Dec 27 2018 16:34 UTC
Apparently hah
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 UTC
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
@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 UTC
:wave:
@JLuboff what's up
Jason Luboff
@JLuboff
Dec 27 2018 19:19 UTC
@cmccormack Hey man, whats happening?
Christopher McCormack
@cmccormack
Dec 27 2018 19:20 UTC
@JLuboff nm man working some FCC Pull Requests
How was your holiday?
Jason Luboff
@JLuboff
Dec 27 2018 19:21 UTC
Not too bad...nothing too exciting but no complaints there heh.. You?
Christopher McCormack
@cmccormack
Dec 27 2018 19:22 UTC
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 UTC
Jeez
Thats a lot
Christopher McCormack
@cmccormack
Dec 27 2018 19:23 UTC
started up a new app as well, personal one
Jason Luboff
@JLuboff
Dec 27 2018 19:23 UTC
Nice, what're you building?
Christopher McCormack
@cmccormack
Dec 27 2018 19:23 UTC
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 UTC
Neat
Christopher McCormack
@cmccormack
Dec 27 2018 19:24 UTC
doing anything for yourself this holiday?
Jason Luboff
@JLuboff
Dec 27 2018 19:27 UTC
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 UTC
sleep by 10 I bet haha
Jason Luboff
@JLuboff
Dec 27 2018 19:29 UTC
...perhaps... :P
Do you typically go out on NYE?
Christopher McCormack
@cmccormack
Dec 27 2018 19:38 UTC
@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 UTC
:joy:
Christopher McCormack
@cmccormack
Dec 27 2018 19:38 UTC
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 UTC
Thats the spirit!
Christopher McCormack
@cmccormack
Dec 27 2018 19:45 UTC
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 UTC
sEE YA
Ankur sharma
@ankur1163
Dec 27 2018 19:52 UTC
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 UTC
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 UTC
@ankur1163 Are you familiar with animations in general?
Ankur sharma
@ankur1163
Dec 27 2018 20:43 UTC
yeah
I have played with trasitions and transform properties
@ehutchllew
Jason Luboff
@JLuboff
Dec 27 2018 21:26 UTC
@Pagnito Sounds invigorating
Pagnito
@Pagnito
Dec 27 2018 21:28 UTC
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 UTC
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 UTC
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 UTC
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 UTC
ok so I could do string literal for that
Jason Luboff
@JLuboff
Dec 27 2018 21:38 UTC
Ya
let favoriteMove = `{
  "title": "Black Panther",
  "director": "Ryan Coogler",
  "year": 2018,
  "imdb":7.5
}`;
Karma Drukpa
@coderkarma
Dec 27 2018 21:38 UTC
no $ sign
Jason Luboff
@JLuboff
Dec 27 2018 21:40 UTC
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 UTC
why that didn't work even using backtick ?
Jason Luboff
@JLuboff
Dec 27 2018 21:42 UTC
It does work.. what do you currently have?
Karma Drukpa
@coderkarma
Dec 27 2018 21:46 UTC
thanks, sorry i was looking in my console. I forgot to refresh
Jason Luboff
@JLuboff
Dec 27 2018 21:46 UTC
:D