These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Jun 2018
Joseph
@revisualize
Jun 23 2018 02:32
@JLuboff - You here?
黄易
@hyxieshi
Jun 23 2018 04:03
md 抽了
我考
Dhaval Vira
@dhavalveera
Jun 23 2018 04:04
post your Question in English only, no other Languages are accepted @hyxieshi
黄易
@hyxieshi
Jun 23 2018 04:06
I don't know much English. I have to use translation software.=-=
Joseph
@revisualize
Jun 23 2018 05:33
@hyxieshi Using translation software is ok.
mpmaan
@mpmaan
Jun 23 2018 05:57
if arr=[1,2,3] then doing arr.slice().splice(1,1) will mutate arr?
Markus Kiili
@Masd925
Jun 23 2018 06:47
@mpmaan No, because slice part makes a copy. arr = arr.slice().splice(1,1)would mutate arr.
mpmaan
@mpmaan
Jun 23 2018 06:55
@Masd925 that's what i thought but i can't pass this challenge
this is what i wrote
 case 'REMOVE_ITEM':
      return state.slice().splice(action.index, 1);
Aditya
@ezioda004
Jun 23 2018 07:05

@mpmaan .splice() returns the removed part of the array. So you're returning the spliced part and not the array.
Something like

const newState = state.slice();
newState.splice(action.index, 1);
return newState;

should work.

mpmaan
@mpmaan
Jun 23 2018 07:06
ok cool
Joseph
@revisualize
Jun 23 2018 08:48
@Masd925 So I need some advice...
I have two job offers. 3k/yr difference in pay.
Jr. Sys Admin for a company with a desk that I'd be at every day. The commute is 15min from my house by bus. I'd only need to commute to Alaska twice a year for the desk job.
Other is for a Managed Service Provider (MSP) where I'd be doing IT support for smaller companies that don't have an IT department. I'd be a Network Engineer commuting around to the businesses doing support every day.
I don't drive so, I'd need to "Uber Everywhere". (Company paid) I'd be working with random tech solving random issues all the time.
I don't know how or if I'd like commuting around to small companies all the damn time.
Or if I just want to accept a desk job where I'd need to commute to Alaska twice a year for 3 days each time. The commute from my apartment to my desk would be 15min by bus.
vs with the MSP ... I'd be dropping into random businesses doing IT support for whatever random issue that comes across.
I've been told by my sister that constantly commuting around gets old REAL fast.... Like real fast.
Or I could take the Network Engineer title and job and see a bunch of shit for 6 to 9 months... Then jump ship. But still 6 to 9 months of a grind.
...
I also did BOMB an interview yesterday. It was pretty bad.
Markus Kiili
@Masd925
Jun 23 2018 08:51
@revisualize Would you learn something of value on that Network engineer job? Or is it just for better pay?
Joseph
@revisualize
Jun 23 2018 08:56
@Masd925 It's just a b.s. title for 3k more a year.
Markus Kiili
@Masd925
Jun 23 2018 08:58
@revisualize Hard to say about you, but I would avoid the commuting if I could manage with the lesser pay.
Joseph
@revisualize
Jun 23 2018 08:58
@Masd925 The Network Engineer title is just a support engineer job with a high end title.
Joseph
@revisualize
Jun 23 2018 09:11
I think everyone is telling me the same thing.
I think I actually agree.
let filtered = watchList.filter((obj)=> obj.Director = "Christopher Nolan");
let arrLength = filtered.length;
let averageRating = filtered.reduce((accumulator, currentVal) => (accumulator + Number(currentVal.imdbRating)), 0);
let result = averageRating / arrLength;
when i do it like this averageRating = filtered.reduce((accumulator, currentVal) => (accumulator + Number(currentVal.imdbRating)) / arrLength, 0); it will give false result
Markus Kiili
@Masd925
Jun 23 2018 09:38
@AymenAlSalem Maybe (accumulator + Number(currentVal.imdbRating)/arrLength) , 0 is the correct place for the divider.
Aymen
@AymenAlSalem
Jun 23 2018 09:41
Thanks you so much @Masd925
Aymen
@AymenAlSalem
Jun 23 2018 10:06
no wonder it didn't pass, I just noticed that i'm re-assigning new value in the filter function... obj.Director = "Christopher Nolan" :D
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 14:38
Hi guys, it's me again hahah
I need some help with my code please

function truthCheck(collection, pre) {
for(var unknown of collection) {
var x = new Boolean(unknown[pre] === true);
}
return x.valueOf();
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

it doesn't work completely
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 14:49
Help please?
Aditya
@ezioda004
Jun 23 2018 15:10
@OGTechnoBoy Any reason why you're strictly checking unknown[pre] against true?
Christopher McCormack
@cmccormack
Jun 23 2018 15:15
@OGTechnoBoy I think you mean to do something like var x = new Boolean(unknown[pre]) === true; correct? Also if it is ever false you should return false immediately from your loop, otherwise if the last item is true you will incorrectly return true
Jack Shijin
@Jackshijin
Jun 23 2018 15:39
how to delete the element in the array with Array.filter()
Christopher McCormack
@cmccormack
Jun 23 2018 15:42
@Jackshijin filter takes a callback, if that callback returns false for that item in the current iteration of the array, it will not be included in the returned array
@Jackshijin
const fruits = ["Apple", "Banana", "Cherry", "Durian"]
const filteredFruits = fruits.filter(function(item) { return item !== "Banana"})
console.log(filteredFruits) // ["Apple", "Cherry", "Durian"]
Christopher McCormack
@cmccormack
Jun 23 2018 15:56
A slightly more complex example:
const fruits = ["Apple", "Banana", "Cherry", "Durian"]
const excludedFruits = ["Banana", "Durian"]
const filteredFruits = fruits.filter(function(item) { return !(excludedFruits.indexOf(item) >= 0)})
console.log(filteredFruits) // ["Apple", "Cherry"]
Jack Shijin
@Jackshijin
Jun 23 2018 16:20
excludedFruits.indexOf(item) -----what will it return @cmccormack
thank you
Markus Kiili
@Masd925
Jun 23 2018 16:24
@Jackshijin IndexOf returns the first index of given value, or -1 if the value is not found on the array.
Pjdaze
@Pjdaze
Jun 23 2018 17:16
hi peeps long time no chat , question.. i'm going through the new better looking es6 javascript challenges .. and well i even did again the basic ones and i encountered differences hehe!
the repeat a string challenge doesn't allow u to use the repeat method anymore lol here is my solution pretty straight forward and of course i can use 2 for loops but if anyone can share different solutions it would be awesome ..
function repeatStringNumTimes(str, num) {

  let arr = [];
for(let i = 0; i < num; i++){

arr.push(i)
}
return arr.map(x => str).join('')

}

repeatStringNumTimes("abc", 5);
Nate Mallison
@NJM8
Jun 23 2018 17:20
anyone have a way to deal with eslint and css files?
Pjdaze
@Pjdaze
Jun 23 2018 17:28
my convo of eslint and prettier works great...
Nate Mallison
@NJM8
Jun 23 2018 17:31
prettier for css yeah? does it support stuff like so?
Aditya
@ezioda004
Jun 23 2018 17:31
@Pjdaze Another way with reduce
function repeatStringNumTimes(str, num) {
  return num >=0 ? Array.from(Array(num).keys()).reduce(accum => accum += str, "") : "" ;
}
Nate Mallison
@NJM8
Jun 23 2018 17:31
 @tailwind utilities;

  .app-card {
    @apply .rounded .shadow-lg .text-center .bg-grey-lightest .my-4 .mx-auto .px-6 .py-2
  }
eslint complaining about the @ symbol
Pjdaze
@Pjdaze
Jun 23 2018 17:33
@ezioda004 freaking sweet !
Aditya
@ezioda004
Jun 23 2018 17:35
@Pjdaze Btw in your code you could simply concatenate in an empty string and return the result.
Something like this
let finalStr = "";
  for(let i = 0; i < num; i++){
     finalStr+=str;
  }
return finalStr;
Markus Kiili
@Masd925
Jun 23 2018 17:39
@Pjdaze It is also always a good time to rehearse recursion:
function repeatStringNumTimes(str, num) {
    if (num===0) return "";
    return str+repeatStringNumTimes(str,num-1);
}
Ogundele Olumide
@Lumexralph
Jun 23 2018 17:40
@Masd925 Hey man :wave: glad to be back here... always seems like second home
Markus Kiili
@Masd925
Jun 23 2018 17:50
@Lumexralph Welcome back!
Nate Mallison
@NJM8
Jun 23 2018 17:51
anyone can tell my why I can't get eslint to ignore my css file?
path from .eslistignore is src/assets/styles/main.css
Ogundele Olumide
@Lumexralph
Jun 23 2018 17:52
@NJM8 have you tried ignoring the directory styles ?
Nate Mallison
@NJM8
Jun 23 2018 17:52
I tried *.css, **/*.css, src/assets/styles/main.css
like so? src/assets/styles
Ogundele Olumide
@Lumexralph
Jun 23 2018 17:54
@Masd925 thank you
@NJM8 yes, try that see if it ignores it
Nate Mallison
@NJM8
Jun 23 2018 17:59
nope
also tried /src/assets/styles and /src/assets/styles/main.css
I like how to documentation says that **/*.js will ignore all js files and **/*.css won't ignore all css files
Moisés Man
@moigithub
Jun 23 2018 18:00
its ur file name correct ? eslistignore (/n)
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:00
@NJM8 this is interesting, have you tried ignoring any other file? did it work?
Nate Mallison
@NJM8
Jun 23 2018 18:01
the file is provided by vue-cli
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:01
@NJM8 what @moigithub said too is worth looking at
Nate Mallison
@NJM8
Jun 23 2018 18:02
tried **.*js and it worked immediately
ohhh. it's not eslint
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:05
@NJM8 I would like to know the cause.... also you would have to have a .eslintignore file if you don't have it yet
Nate Mallison
@NJM8
Jun 23 2018 18:07
Screen Shot 2018-06-23 at 2.06.57 PM.png
not sure where its coming from maybe Vscode
just says [css]
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:09
maybe you try checking that online maybe follow the link see what it's about
Nate Mallison
@NJM8
Jun 23 2018 18:12
Microsoft/vscode#14999
supposed to have been fixed
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:13
@NJM8 I really don't have knowledge about that, maybe there's a way around it
Nate Mallison
@NJM8
Jun 23 2018 18:15
yeah I asked about it on vscode channel here
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:16
@NJM8 cool
using vue right?
Nate Mallison
@NJM8
Jun 23 2018 18:17
yes
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:17
cool... hopefully I'll join the train soon
Nate Mallison
@NJM8
Jun 23 2018 18:18
do it, vue is great
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:20
yeah so I read but still have a lot of react stuffs to do. i will do vue as a side project given time
Nate Mallison
@NJM8
Jun 23 2018 18:23
highly recommend this course
so good
Pjdaze
@Pjdaze
Jun 23 2018 18:27
@Masd925 i think i'm never going to get recursion
:( so sad
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:29
@Pjdaze you'll just take time with it
Pjdaze
@Pjdaze
Jun 23 2018 18:31
i guess ... i gave up so much i really don't even know what it means or does exactly :(
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:33
I think a good place to start is understanding the theory and concept behind it, then start applying in bits as you understand it
Pjdaze
@Pjdaze
Jun 23 2018 18:35
i will i have to
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:36
cool
Nate Mallison
@NJM8
Jun 23 2018 18:36
@Pjdaze to understand recursion you first have to understand recursion
little cs joke there
Pjdaze
@Pjdaze
Jun 23 2018 18:37
lol well i dont get it at all
i have a learning disab
when it gets to crazy i freak
Ogundele Olumide
@Lumexralph
Jun 23 2018 18:40
lol.... use your learning style to conquer recursion
Aditya
@ezioda004
Jun 23 2018 18:40
@Pjdaze Try this in console and step into the function, it might help
function repeatStringNumTimes(str, num) {
    debugger;
    if (num===0) return "";
    return str+repeatStringNumTimes(str,num-1);
}
repeatStringNumTimes("abc", 5);
Markus Kiili
@Masd925
Jun 23 2018 18:42
@Pjdaze The concept of recursion needs you to understand the concepts of function calls and arguments and parameters. To understand those, you need to understand the concept of an execution context. You just have to take one example and really go through what is happening under the hood.
Moisés Man
@moigithub
Jun 23 2018 18:42

also.. there are some explanations on youtube

https://www.youtube.com/watch?v=Mv9NEXX1VHc
https://www.youtube.com/watch?v=k7-N8R0-KY4

Nate Mallison
@NJM8
Jun 23 2018 18:42
function printNums (num) {
  for (let i = 0; i < num; i++) {
    console.log(num)
  }
}

function recurPrintNums (num) {
  console.log(num)

  if (num === 0) {
    return
  } else (
    recurPrintNums(num - 1)
  )
}
everyone getting in on the recursion examples, haha
Christopher McCormack
@cmccormack
Jun 23 2018 19:33
Anyone here familiar with React and/or want to help me test something?
You don't necessarily need to know anything about react but it would help to know how to use npm/git
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:36
Guys I didn't understand smallest common multiple challenge
Can anyone explain it to me?
Christopher McCormack
@cmccormack
Jun 23 2018 19:36
Which part @OGTechnoBoy ?
The problem is that I didn't understand anything from it.
I know smallest common multiple
But it got explained different in that lesson, I think it uses range or something like that
Christopher McCormack
@cmccormack
Jun 23 2018 19:39
Yeah so not only do you need to find the SCM of the two numbers but also the integers between those two numbers
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:39
I didn't understand
what do you mean with "integers between those 2 numbers"?
Christopher McCormack
@cmccormack
Jun 23 2018 19:39
So the example they give, the SCM would have to be divisible by 1 and 3 but also by all numbers in between. In that case it would also have to be divisible by 2
All values between two numbers, so given 2 and 5 the values between would be 3, 4
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:40
So let me get this straight
First we search SCM of the two numbers
But with 1 condition is that it has to be divisible by the numbers in range?
Right?
Christopher McCormack
@cmccormack
Jun 23 2018 19:41

First we search SCM of the two numbers

not sure how relevant this part is

OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:42
What do you mean,
Christopher McCormack
@cmccormack
Jun 23 2018 19:42
it needs to be all of the numbers, so given 1 and 5, you need to find the SCM of 1,2,3,4,5
The example shows 60, and 60 is divisible by 1, 2, 3, 4 and 5, and is the lowest number that fulfills this requirement
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:43
So I guess I will apply the algorithm and edit it to loop it through all the range, right?
Christopher McCormack
@cmccormack
Jun 23 2018 19:43
yeah
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:43
Oooh!
I now understand.
It's not least common devisor
It's least common multiple
Christopher McCormack
@cmccormack
Jun 23 2018 19:44
One trick you can use is to increment by the largest number in your range, so your loop doesn't have to run as long
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:44
No wonder I didn't understand haahah
Christopher McCormack
@cmccormack
Jun 23 2018 19:44
right
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:44
Thank you a lot for the explaination!
Christopher McCormack
@cmccormack
Jun 23 2018 19:45
no problem
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:45
Nevermind.
Wait, shouldn't I decrease by -1 everytime the loop runs?
Why I should increment?
Christopher McCormack
@cmccormack
Jun 23 2018 19:47
Go ahead and start coding it and see what you think is best :)
OGTechnoBoy
@OGTechnoBoy
Jun 23 2018 19:47
Okay. Thanks again.
Pjdaze
@Pjdaze
Jun 23 2018 20:41
thanks a lot! @ezioda004 @Masd925
i was away for a sec but ok so i see where the function calls itself like they always explain, but ok, when we are calling the function what does the arguments mean since we are using the same as params...