These are chat archives for FreeCodeCamp/HelpJavaScript

19th
Sep 2017
Nick Cleary
@Hijerboa
Sep 19 2017 01:26
quick question: how do we deal with the fact that some of the test cases in the Arguments Optional challenge (https://www.freecodecamp.org/challenges/arguments-optional) throw an error when you try to run them? kinda hard to do when the built in functions break JS syntax
wait... when i try to run the code for the challenge locally it throws and error but when i put it into FCC it's just like "kay thats cool"
wth
nvm then
Ken Haduch
@khaduch
Sep 19 2017 01:31
@Hijerboa - where do you throw these errors? And what does your code look like - maybe something with a latent bug that only shows up in certain conditions?
Nick Cleary
@Hijerboa
Sep 19 2017 01:32
@khaduch Here's my code:
function addTogether() {
  if(isNaN(arguments[0]) || isNaN(arguments[1]) || typeof arguments[0] == "string" || typeof arguments[1] == "string"){
    console.log("undefined");
    return undefined;
  } else if(typeof arguments[0] == "number" && typeof arguments[1] == "number"){
    console.log(arguments[0] + arguments[1]);
    return (arguments[0] + arguments[1]);
  }
  return false;
}
addTogether(2,3);
addTogether(2)(3);
addTogether("http://bit.ly/IqT6zt");
addTogether(2, "3");
addTogether(2)([3]);
and here's the error: Uncaught TypeError: addTogether(...) is not a function
whenever I write the code in atom then run it, I get this error when any of the "non standard" test cases are allowed to be callled. But when I do it in FCC's IDE it works fine
which is strange
Ken Haduch
@khaduch
Sep 19 2017 01:34
@Hijerboa - you are missing something.... There should be some cases where you return a function that will be called with a second argument - the cases that look something like this: addTogether(2)(3)
Nick Cleary
@Hijerboa
Sep 19 2017 01:34
I didn't include the cases in the code
just added them
Ken Haduch
@khaduch
Sep 19 2017 01:36
@khaduch - there are two different cases - if you disregard the error cases. The one where you pass two valid arguments, like the first one, you just add the numbers and return them. The ones that have the two parentheses with valid arguments have to return a function. The function that is returned should have the first argument used in closure, so that it is available when you call the function with the second argument.
Nick Cleary
@Hijerboa
Sep 19 2017 01:38
The issue isn't that the code itself doesn't work persay (I haven't actually coded the second case). The issue is that when I run the code that I create in any environment other than FCC it throws the aforementioned error. Therefore anything I would code for that case would be pointless, as it would simply see the "non standard case" the throw said error
Ken Haduch
@khaduch
Sep 19 2017 01:38
@Hijerboa - that comment was meant for you, not me... :) :point_up: September 18, 2017 9:36 PM
Nick Cleary
@Hijerboa
Sep 19 2017 01:38
Its not really big deal... more just a wierd quirk of the test cases
@khaduch and i got that haha :P
Ken Haduch
@khaduch
Sep 19 2017 01:40
@Hijerboa - well, the test environment must be running all of the testcases and the ones that have the two sets of parens must be failing. The errors will only occur during runtime and you wont' see them (or not necessarily see them) in the little console window. If you put the case addTogether(2)(3) as the lone invocation of the function at the bottom of the code window, I think that you'll see your error show up then? I'd have to go and try that to verify it.
@Hijerboa - indeed it works that way - if you have your function call as addTogether(2)(3); with your code, you will see the error in the output window below the "Ask for help on the forum" button.
Nick Cleary
@Hijerboa
Sep 19 2017 01:43
@khaduch well thats interesting
might be worth opening an issue on the github repo about this challenge
because that might throw some people off... myself included
@khaduch thanks for helping me figure that out lol
CamperBot
@camperbot
Sep 19 2017 01:44
hijerboa sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3298 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Sep 19 2017 01:46
@Hijerboa - that window only captures the output from the last function invocation in the editor window - you really have to go by the results of the individual tests, and if you have errors passing them, you can put the particular test case in the editor to see it, or use another code development tool like jsbin.com where you can see all of the errors that might occur with multiple function invocations.
Nick Cleary
@Hijerboa
Sep 19 2017 01:48
@khaduch yeah that's I plan to do. Just annoying lol
ArchivalBoat50
@ArchivalBoat50
Sep 19 2017 02:46
Hey guys what are all these errors appearing in my console? https://codepen.io/ArchivalBoat50/pen/JyPVbd
legendinraze
@legendinraze
Sep 19 2017 04:17
I don't understand else Satement, please help
this is what I have
function testElse(val) {
  var result = "";
  // Only change code below this line

  if/else (val > 5 || val <= 5) {
    result = "Bigger than 5";
    result = "5 or Smaller";
  }




  // Only change code above this line
  return result;
}

// Change this value to test
testElse(4);
Ken Haduch
@khaduch
Sep 19 2017 04:27
@legendinraze - what you have written there is not correct - there is no if/else statement.
ArchivalBoat50
@ArchivalBoat50
Sep 19 2017 04:37
Hey guys what are all these errors appearing in my console? https://codepen.io/ArchivalBoat50/pen/JyPVbd
Ken Haduch
@khaduch
Sep 19 2017 04:39

@legendinraze - if you are supposed to return a status "Bigger than 5", you can detect that with a statement like this:

if ( val > 5) {
    result = "Bigger than 5";
}

then any other value that is less than 5 could be reported in the else statement.

if (val > 5) {
    result = "Bigger than 5";
} else {
    result = "5 or smaller";
}

So one or the other situation is detected. Not sure if that helps you?

@ArchivalBoat50 - I don't really see errors in your console? You are getting the objects reported as you receive the data? What errors are you seeing?
@ArchivalBoat50 - some of the requests are returning status for channels that cannot be found? Is that what you are referring to?
ArchivalBoat50
@ArchivalBoat50
Sep 19 2017 04:42
it says there are 52 errors and 1 warning @khaduch
those errors say returned a 403
Ken Haduch
@khaduch
Sep 19 2017 04:44
@ArchivalBoat50 - when I just load the page there are 13 warnings, at least that's what I'm seeing - but it's coming from some chrome extension that I have loaded, so I don't know if it would be the same thing that you're seeing?
ArchivalBoat50
@ArchivalBoat50
Sep 19 2017 04:45
errors.png
@khaduch Idk lmao
Ken Haduch
@khaduch
Sep 19 2017 04:50
@ArchivalBoat50 - well, I don't see that in my browser window - but this wikipedia page explains a lot about that error. Here is a screenshot of my browser console (using the Opera browser on Windows 10)
image.png
which browser are you using?
not that it would make a difference?
ArchivalBoat50
@ArchivalBoat50
Sep 19 2017 04:52
@khaduch Im using chrome
Ken Haduch
@khaduch
Sep 19 2017 04:59
@ArchivalBoat50 - I see one error reported on Chrome - I think that it has something to do with an ad blocker? It could be that you are running into things because of extensions or things that you have enabled? For the most part, I'm seeing data returned from your calls to the API.
mambasnoww
@mambasnoww
Sep 19 2017 05:00
can someone help me with some javascript trying to do a for loop the iterates through a table with two columns idk how to do that
Ken Haduch
@khaduch
Sep 19 2017 05:01
@mambasnoww - someone could help you - can you be more specific about what you're trying to do? Post some code or a URL to your code?
mambasnoww
@mambasnoww
Sep 19 2017 05:02
"Using a For loop, create a script that adds an eight percent tax to sales transactions ranging from 1 and 50 dollars.
Display both the Sales and Total figures in consecutive rows of a table."
Ken Haduch
@khaduch
Sep 19 2017 05:04
@mambasnoww - is this a freeCodeCamp lesson or challenge? What kind of data do they give you - just an array of sales values as input?
mambasnoww
@mambasnoww
Sep 19 2017 05:06
its a challenge im suppose to iterate a for loop with values 1-50
and make a row for every number and display the total value in each for for the total column
ArchivalBoat50
@ArchivalBoat50
Sep 19 2017 05:08
@khaduch Hmm I don't think it matters much anyways. I'll see when it interferes with my app. Thanks for your help :)
CamperBot
@camperbot
Sep 19 2017 05:08
archivalboat50 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3299 | @khaduch |http://www.freecodecamp.com/khaduch
mambasnoww
@mambasnoww
Sep 19 2017 05:12
This is what i have so far

<!doctype html>

<html lang="en">
<head>
<title>for loop</title>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>

<body>

<!-- JAVASCRIPT -->
<script type="text/javascript">
document.write('<table>');
document.write('<tr><th>Sales</th><th>Total</th></tr>');
for(var i = 0; i <50; i++) { document.write('<tr><td>' + [i] + '</td></tr>'); } document.write('</table>'); </script>
<!-- END JAVASCRIPT -->
</body>
</html>

Ken Haduch
@khaduch
Sep 19 2017 05:13

@mambasnoww - oh, this would be the basic code - if they want you to generate an HTML table you have to add HTML markup to it. The basic code would look like this:

for ( var i = 1; i <= 50; i++) {
    var total = i + i * 0.08;
    console.log(i, total);
}

In the console, you would get this (The "Scratchpad" stuff is coming from the firefox devtools, I removed it for the first few lines of output):

1 1.08  
2 2.16  
3 3.24 
4 4.32  
5 5.4  
6 6.48  
7 7.5600000000000005  
8 8.64  
9 9.72  Scratchpad/1:12:5
10 10.8  Scratchpad/1:12:5
11 11.88  Scratchpad/1:12:5
12 12.96  Scratchpad/1:12:5
13 14.04  Scratchpad/1:12:5
14 15.120000000000001  Scratchpad/1:12:5
15 16.2  Scratchpad/1:12:5
16 17.28  Scratchpad/1:12:5
17 18.36  Scratchpad/1:12:5
18 19.44  Scratchpad/1:12:5
19 20.52  Scratchpad/1:12:5
20 21.6

on up to 50 54
There are things that you can do to format the data.
Does this do anything to help you with understanding the problem?

@mambasnoww - is that generating anything for you at this point? Let me copy your code to a jsbin and see what happens.
This i what i have so far
not sure how to add the html markup to the for loop
Ken Haduch
@khaduch
Sep 19 2017 05:21
@mambasnoww - if you just make that line that is outputting your rows into this: document.write('<tr><td>' + [i] + '</td><td>' + [i+i*0.08] + '</td></tr>'); } then you have the basic data, I think?
that's using the code that you have above.
@mambasnoww - I have to run along - this is a version that seems to be close to what you want: http://jsbin.com/mumujaz/1/edit?html,js,output - based on the code that you posted above.
mambasnoww
@mambasnoww
Sep 19 2017 05:25
Oh ok ken
I undersetand how to format that now
THANK YOU @khaduch
CamperBot
@camperbot
Sep 19 2017 05:25
mambasnoww sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3300 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Sep 19 2017 05:26
@mambasnoww - great! You're welcome and good luck finishing it!
june577680085
@june577680085
Sep 19 2017 06:28
a code of palindrome------------I need some help,please.
function palindrome(str) {
// 请把你的代码写在这里
str.replace(/" "/g,'');
str.toLowerCase();
var arr=str.split("");
arr.reverse();
str=arr.join();
return true;
}
palindrome("eye");
Markus Kiili
@Masd925
Sep 19 2017 06:29
@june577680085 You need to remove all the non-alphanumeric characters first.
june577680085
@june577680085
Sep 19 2017 06:35
@Masd925
@Masd925 how to remove?
Markus Kiili
@Masd925
Sep 19 2017 06:36
@june577680085 You need to make a suitable regexp object to use with replace. Look at metacharacters \w and \W.
june577680085
@june577680085
Sep 19 2017 06:52
@Masd925 function palindrome(str) {
// 请把你的代码写在这里
str.replace(/[^\w]/g,"");
str.toLowerCase();
var arr=str.split("");
arr.reverse();
var str1=arr.join("");
return str1==str;
}
palindrome("eye");
yofri
@yofriadi
Sep 19 2017 07:18
guys 222*2 = 16. how do i know the base number, if i only know 16?
i mean 2*2*2*2
sorry, my bad. it must number 2 but how much times i do i have to know is the question
Markus Kiili
@Masd925
Sep 19 2017 07:21
@Yofri Do you mean how many times do you have to multiply 2 by itself to get 16?
yofri
@yofriadi
Sep 19 2017 07:22
@Masd925 yes
Markus Kiili
@Masd925
Sep 19 2017 07:22
@Yofri
Math.log(32)/Math.log(2); // 5
yofri
@yofriadi
Sep 19 2017 07:24
@Masd925 wow thanks man, i never meet this Math.log()
CamperBot
@camperbot
Sep 19 2017 07:24
yofri sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4491 | @masd925 |http://www.freecodecamp.com/masd925
june577680085
@june577680085
Sep 19 2017 07:25
@Masd925 I just found a piece of code, it's ok,I couldn't get you fully because of the barrier of language,and thank you for your help :).function palindrome(str) {
str = str.toLowerCase().replace(/[^\w]|_/g, "");
return str.split("").reverse().join("") === str;
}
palindrome("neveroddorev en");
CamperBot
@camperbot
Sep 19 2017 07:25
june577680085 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4492 | @masd925 |http://www.freecodecamp.com/masd925
linkin-park
@linkin-park
Sep 19 2017 07:35
javascript is heck hard!
who came up with generators ?
why we need class
linkin-park
@linkin-park
Sep 19 2017 07:40
it sucks!
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 07:47
good morning everyone
https://www.codewars.com/kata/array-helpers/train/javascript cansomeone explain me what's the idea here?got a bit confused
linkin-park
@linkin-park
Sep 19 2017 07:51
is that 6 KYU unbelievable
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 07:53
create array.prototypes?
linkin-park
@linkin-park
Sep 19 2017 08:17
not required :)
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 08:18
atually that's the idea of the exercise but thanks
Yaroslav
@YariPL
Sep 19 2017 08:36

hi. task is "Use filter to create a new array with all the values from oldArray which are less than 6. The oldArray should not change."

var oldArray = [1,2,3,4,5,6,7,8,9,10].filter(function(lala) {
return lala < 6;
});

// Only change code below this line.
var newArray;
newArray =lala;

what's wrong with this?

Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 08:37
lala.length?
you mean the vcalue nm
you need to return the result contained inside oldarray
after the filter write return oldArray;
Yaroslav
@YariPL
Sep 19 2017 08:39
return oldArray < 6; ?
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 08:40
var oldArray = [1,2,3,4,5,6,7,8,9,10].filter(function(lala) {
return lala < 6;
});
return oldArray;
you are storing the results of the filter array in the old array
so you have to return it after the filter cause it contains the filtered values
Pethaf
@Pethaf
Sep 19 2017 08:41
By the way.
When watching video tutorials and finding yourselves stuck on concepts that aren't properly explained. Do you just watch on or do you try to find supplementary materials?
Yaroslav
@YariPL
Sep 19 2017 08:44
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 08:44
@YariPL worked?
Yaroslav
@YariPL
Sep 19 2017 08:45
not yet
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 08:45
@YariPL tried it on jsbin seems to be working
Yaroslav
@YariPL
Sep 19 2017 08:47

var oldArray = [1,2,3,4,5,6,7,8,9,10];

var newArray = oldArray.filter(function(val) {
return val < 6;
});

this one works. I tried to do filter with a new array as in the description.
btw thanks much for your help)

Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 08:48
@YariPL you can return directly the v alue taht comes out of the filter instead of setting it to a variable just do it like return oldArray.filter(function(val) {
return val < 6;
});
Pethaf
@Pethaf
Sep 19 2017 08:48
@YariPL I don't think MDN covers react.
Yaroslav
@YariPL
Sep 19 2017 08:50
@Pethaf I tried to find some similar courses which will fulfill the gaps but most of them are not free as FCC
linkin-park
@linkin-park
Sep 19 2017 08:59
i dont like class in js , should stop using JS ?
Pethaf
@Pethaf
Sep 19 2017 09:02
What is your end goal?
Blauelf
@Blauelf
Sep 19 2017 09:03
Interesting. As GitHub is blocked here (so I cannot login), I transplanted a gitter.im session from my phone. No spelling mistakes it seems. Nice.
Markus Kiili
@Masd925
Sep 19 2017 09:07
@linkin-park You don't need to use classes in JS. They are just syntax sugar.
linkin-park
@linkin-park
Sep 19 2017 09:18
thanks @Masd925 , what was the main reason they got that thing here ?
CamperBot
@camperbot
Sep 19 2017 09:18
linkin-park sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4493 | @masd925 |http://www.freecodecamp.com/masd925
Blauelf
@Blauelf
Sep 19 2017 09:19
Classes can make some code a bit clearer. Especially the super keyword is nice if you come from an OO background.
Markus Kiili
@Masd925
Sep 19 2017 09:20
@linkin-park Maybe it is easier to learn JS if you come from some class based language then.
Blauelf
@Blauelf
Sep 19 2017 09:22
JavaScript itself is not at all similar to those languages it tries to imitate with its class keyword.
Pethaf
@Pethaf
Sep 19 2017 09:28
Depends.
Blauelf
@Blauelf
Sep 19 2017 09:29
For example, JavaScript's prototype chain does not allow for multiple inheritance, which is supported by for example Python and Java (with certain restrictions, like Java only being able to implement multiple interfaces, but not inherit from multiple classes)
linkin-park
@linkin-park
Sep 19 2017 09:35
i know that :/
Blauelf
@Blauelf
Sep 19 2017 09:37
One can use Object.create and Object.assign to fake something like that, but changes in the copied prototypes won't be reflected.
linkin-park
@linkin-park
Sep 19 2017 09:39
your right
Pethaf
@Pethaf
Sep 19 2017 09:39
Comming from a C++ background.
Multiple inheritance is very rarely worth it.
Learn from the Gang Of Four instead, favor composition over inheritance.
devpaaji
@devpaaji
Sep 19 2017 10:32
hellio
@Blauelf
Markus Kiili
@Masd925
Sep 19 2017 10:49
@devpaaji You have to lure him here: sort, sort, bratwurst, bratwurst!
Munkhmanlai
@munkhmanlai
Sep 19 2017 10:53

[{"GOV":[
{
"date": "2014-01-01T16:00:00.000Z",
"value": 5800,
"volume": 1
},
{
"date": "2014-01-06T16:00:00.000Z",
"value": 5750,
"volume": 1
},
{
"date": "2014-01-07T16:00:00.000Z",
"value": 5375,
"volume": 56
},
{
"date": "2014-01-08T16:00:00.000Z",
"value": 5600,
"volume": 20
}
],{"MIK":[
{
"date": "2016-01-03T16:00:00.000Z",
"value": 12100,
"volume": 3056
},
{
"date": "2016-01-04T16:00:00.000Z",
"value": 12180,
"volume": 107
},
{
"date": "2016-01-05T16:00:00.000Z",
"value": 12200,
"volume": 1120
},
{
"date": "2016-01-06T16:00:00.000Z",
"value": 12200,
"volume": 2022
}
]}]

I have this JSON file and when you hit search button, it is supposed to search JSON file and "MIK","GOV" will be what is searched, those are company names and when MIK is written and hit search button it is supposed to display the latest price of MIK is there anyone can help me thanks

Blauelf
@Blauelf
Sep 19 2017 11:03

@munkhmanlai Something like

var name = "GOV";
var list = data[0][name];
if (list && list.length) {
  console.log(list[list.length-1].value); // logs 5600
}

(assuming entries are ordered and your data structure is named data)
?

Dan Couper
@DanCouper
Sep 19 2017 11:21
Again assuming entries are ordered (though could just add a sort in there if not), can do
function search(term, jsonData) {
     const data = jsonData.find(datum => datum.hasOwnProperty(term));
     if (data) {
          return data[data.length - 1].value;
     }
}
Munkhmanlai
@munkhmanlai
Sep 19 2017 11:28
@Blauelf can you do it in jquery
???
linkin-park
@linkin-park
Sep 19 2017 11:32
Kei Nart
@codenart
Sep 19 2017 11:38
@linkin-park nice one :sparkles:
This is mine. :D
function diffArray(arr1, arr2) {
  return arr1.concat(arr2)
             .sort()
             .filter(function(ele, idx, arr) {
               return ! (ele == arr[idx-1] || ele == arr[idx+1]);
             });
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Markus Kiili
@Masd925
Sep 19 2017 11:39
@codenart The default sort is not numerical sorting.
Maybe it doesn't matter here?
alpox
@alpox
Sep 19 2017 11:42
@Masd925 Does only not matter because all numbers are < 10
Kei Nart
@codenart
Sep 19 2017 11:43

@Masd925 https://www.freecodecamp.org/challenges/diff-two-arrays
Base on the given test cases. It's not only about working with numerical data.

Yes. It's not numerical sorting. But it can make sure all the same values will be hand by hand.

Markus Kiili
@Masd925
Sep 19 2017 11:43
@alpox It might not matter with larger numbers either.
alpox
@alpox
Sep 19 2017 11:43
@Masd925 Well alphabetical would say that 15 < 3
Markus Kiili
@Masd925
Sep 19 2017 11:44
@alpox I think it only matters that same numbers are next to each other with this logic.
linkin-park
@linkin-park
Sep 19 2017 11:44
sort is tricky it goes with unicode :P until you do another foo handling with fn , but there is another scenario it may occur :/ so i avoided concat
alpox
@alpox
Sep 19 2017 11:45
@Masd925 Hmm right after reading the challenge again i'm with you that it shouldn't matter here
linkin-park
@linkin-park
Sep 19 2017 11:45
O(nlogn) solution are good :) better if its map but i like Foo fun
Markus Kiili
@Masd925
Sep 19 2017 11:47
@codenart Yes, you are correct. There can be other values too.
alpox
@alpox
Sep 19 2017 11:49
@linkin-park There might be a O(n) solution for this?
linkin-park
@linkin-park
Sep 19 2017 11:49
if arr1 = [1,1,2,3] arr2=[2]
it must return [1,1,3]
Kei Nart
@codenart
Sep 19 2017 11:50
Have u tried my solution yet? :D
linkin-park
@linkin-park
Sep 19 2017 11:50
ya it fails
@Masd925 is map is better for this ?
Kei Nart
@codenart
Sep 19 2017 11:51
so why fcc make me pass :v:
Markus Kiili
@Masd925
Sep 19 2017 11:51
@linkin-park I don't think so.
linkin-park
@linkin-park
Sep 19 2017 11:52
why not @Masd925 ?
Markus Kiili
@Masd925
Sep 19 2017 11:54
@linkin-park Map makes a new array with the same number of elements as in the original, so I don't see how it suit this problem.
linkin-park
@linkin-park
Sep 19 2017 11:55
:/ your right
Blauelf
@Blauelf
Sep 19 2017 11:55
@munkhmanlai This has nothing to do with jQuery or not. Of course you can combine jQuery with my code or that of @DanCouper .
linkin-park
@linkin-park
Sep 19 2017 11:57
@codenart call the FCC cops :D
@codenart file a bug at FCC :)
alpox
@alpox
Sep 19 2017 12:03
function diffArray(arr1, arr2) {
  return Array.from(arr1
    .concat(arr2)
    .reduce((map, item) => {
      if(map.get(item)) map.delete(item);
      else map.set(item, true);
      return map;
    }, new Map())
    .keys());
}
Should be O(n)
Blauelf
@Blauelf
Sep 19 2017 12:04
Are set, delete and get O(1)\mathcal{O}(1)?
Markus Kiili
@Masd925
Sep 19 2017 12:04
Probably not.
alpox
@alpox
Sep 19 2017 12:04
@Blauelf I'm not fully sure but i believe that map is a hash table so it should be
linkin-park @linkin-park looks at es6 feature :/
linkin-park
@linkin-park
Sep 19 2017 12:06
ya its hashtable
everything is hashtable in js
Blauelf
@Blauelf
Sep 19 2017 12:07
Might be O(n)\mathcal{O}(n) for not too many elements, then. Hashtable performance degrades as soon as hash collisions become more frequent (usually behind the "buckets" there are linked lists).
linkin-park
@linkin-park
Sep 19 2017 12:07
but your soln will fail as stated to @codenart
Blauelf
@Blauelf
Sep 19 2017 12:08
You mean because of duplicates within one input array?
alpox
@alpox
Sep 19 2017 12:08
@Blauelf Yes thats true, but one just hopes that there are no or just a few collisions :D
Dan Couper
@DanCouper
Sep 19 2017 12:09
@munkhmanlai jQuery is for DOM manipulation, it's the wrong library for this. If you want a library to make things easier (though this is simple just using JS) use Lodash not jQuery, as this is the kind of problem Lodash is designed to solve. Again though, this is as simple using JS' standard library functions as it is to pull in a library and use that
linkin-park
@linkin-park
Sep 19 2017 12:09
ya @Blauelf
alpox
@alpox
Sep 19 2017 12:10
@linkin-park Ah kk
Yes thats true ^^
Blauelf
@Blauelf
Sep 19 2017 12:12
So not diff two arrays but symmetric difference?
diff two arrays does not test for duplicates within an array. symmetric difference does.
This message was deleted
(Though I think it's never mentioned in the former)
linkin-park @linkin-park googles :/ symmetric what is that
linkin-park @linkin-park okay!
Markus Kiili
@Masd925
Sep 19 2017 12:17
@Blauelf Discussion was always about Diff two arrays.
Blauelf
@Blauelf
Sep 19 2017 12:19

That one is not testing for this case. Also,

Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both.

does not exactly specify what to return if there were duplicates within an input array. One copy of the element? All of them (as they are not in both arrays)?

Blauelf
@Blauelf
Sep 19 2017 12:29
In my opinion, the whole thing makes sense only if I treat the arrays as sets. But sets don't contain duplicates.
alpox
@alpox
Sep 19 2017 12:30
:point_up:
mm1mm2
@mm1mm2
Sep 19 2017 12:38
image.png
I need help......
Antonious Stewart
@Antonious-Stewart
Sep 19 2017 12:40

so i am on the title case challenge and was just wondering if im on the right track this is what i have so far function titleCase(str) {
var begin = str.toLowerCase().split(' ');
for (var i = 0; i < begin.length; i++){

}
return begin;
}

titleCase("I'm a little tea pot");
if not a bit of guidance would be appreciated

Christopher
@bradley1492
Sep 19 2017 12:43

Hello @Masd925 a few months ago you kindly helped me with the https://www.freecodecamp.org/challenges/wherefore-art-thou challenge.

With your help I could manage to write the following code:

function whatIsInAName(collection, source) {
  var arr = [];
  var sourceKey = Object.keys(source);
  var sourceValues = Object.values(source);

  for(var i=0; i<collection.length; i++){
    for(var j=0; j<sourceKey.length; j++){

      if(collection[i][sourceKey[j]] == source[sourceKey[j]] &&                 collection[i].hasOwnProperty(sourceKey[j])){
        arr.push(collection[i]);
      }//end if  

    }//end for 2  
  }//end for 1
  //console.log(arr);

  return arr;

}//end function
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

But my problem is now that I only get the first two cases accepted. The third and the fourth stay unaceppted.

But the if-else statement from my understanding checks the value and the key of each object in the collection array. Somewhere I must be missing something...?

Blauelf
@Blauelf
Sep 19 2017 12:44
@mm1mm2 To call a function, you have to append parentheses, like .toUpperCase()
linkin-park
@linkin-park
Sep 19 2017 12:44
challenge link pls @bradley1492
mm1mm2
@mm1mm2
Sep 19 2017 12:47
@Blauelf I'll try it
Antonious Stewart
@Antonious-Stewart
Sep 19 2017 12:48

so i am on the title case challenge and was just wondering if im on the right track this is what i have so far function titleCase(str) {
var begin = str.toLowerCase().split(' ');
for (var i = 0; i < begin.length; i++){

}
return begin;
}

titleCase("I'm a little tea pot");
if not a bit of guidance would be appreciated

linkin-park
@linkin-park
Sep 19 2017 12:49
title case ? links pls :sparkles:
korzo
@korzo
Sep 19 2017 12:49
@bradley1492 I think for k in sourceis better
mm1mm2
@mm1mm2
Sep 19 2017 12:49
Thanks @Blauelf
CamperBot
@camperbot
Sep 19 2017 12:49
mm1mm2 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4606 | @blauelf |http://www.freecodecamp.com/blauelf
linkin-park
@linkin-park
Sep 19 2017 12:52
@bradley1492 after that you can try :/ https://www.codewars.com/kata/merged-string-checker
Garrus Napp
@GarrusNapp
Sep 19 2017 13:03
what is the difference between var x = {"a": 100}; and var x = {a:100};
korzo
@korzo
Sep 19 2017 13:04
@GarrusNapp it's the same
Garrus Napp
@GarrusNapp
Sep 19 2017 13:05
@korzo ty
CamperBot
@camperbot
Sep 19 2017 13:05
garrusnapp sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
korzo
@korzo
Sep 19 2017 13:05
you don't have to use "" if key name is valid JS key
CamperBot
@camperbot
Sep 19 2017 13:05
:cookie: 511 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Sep 19 2017 13:07
@GarrusNapp You need them for example when key has space
var a = {"hello world" : "!"};
console.log(a["hello world"])
Garrus Napp
@GarrusNapp
Sep 19 2017 13:08
Yea, that I know, I was wondering about such situation: var a = "b"; var x = {a : 100};
Christopher
@bradley1492
Sep 19 2017 13:14
@korzo for k in source? Sorry I don't understand?
@linkin-park merged string checker? What does this do?
korzo
@korzo
Sep 19 2017 13:16
@bradley1492 instead of second for loop. You will save 3 lines
@bradley1492
for(let k in source) {
    if(collection[i][k] === source[k]) arr.push(collection[i]);
}
But the code is wrong, because it fails if source has more then 1 key
Christopher
@bradley1492
Sep 19 2017 13:24

@korzo okay thanks for the for in loop tip, thats a handy one. I'll implement it at the end when I figured out why it fails if source has more than one key.

My thought is that the second for-loop iterates through the source object.

And then in the if else statement I am always refering to sourceKey[j]. This should handle multiple key-value pairs in the source object shouldn't it?

CamperBot
@camperbot
Sep 19 2017 13:24
bradley1492 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 513 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Sep 19 2017 13:37
@bradley1492 Oh snap, you are right. Tests were failing and I got lost in brackets
Anyway, my previous snipped can be fixed with break
    filtering:  {
      for(let k in source) {
        if(collection[i][k] !== source[k]) break filtering;
      }      
      arr.push(collection[i]);
    }
Christopher
@bradley1492
Sep 19 2017 13:38
@korzo so my initial code was right?
But why is it failing then despite not using a for-in loop?
Blauelf
@Blauelf
Sep 19 2017 13:41
The push needs to be in the outer loop, the one over collection.
@korzo You meant continue, not break?
korzo
@korzo
Sep 19 2017 13:42
@bradley1492 If you mean this code then no.
It fails with multiple keys
Christopher
@bradley1492
Sep 19 2017 13:44

@korzo ah ok so I'm wrong. Thats the code I meant.

I can't understand why it fails with multiple keys.

I always think that I am iterating through the objects keys and then refering to them in the for-loop. That should be the step for the function to work with multiple keys in the source object isn't it?

korzo
@korzo
Sep 19 2017 13:45
@Blauelf No. You want to end filtering block if values are not matching
also you can't use continue in this example. It will throw error as block is outside of loop
@bradley1492 For xample, if source has 2 keys.
first key match, you push collection[i] in arr.
second key doesn't match, but collection[i] is already in arr.
Blauelf
@Blauelf
Sep 19 2017 13:46
@korzo Ah, what I meant was more like
    outer: for (let elem of collection) {
      for(let k in source) {
        if(elem[k] !== source[k]) continue outer;
      }
      arr.push(elem);
    }
Christopher
@bradley1492
Sep 19 2017 13:47
@korzo ahhh that makes some sense :)
okay so then I have to find out how I can accomplish that the object only gets pushed to the arr array, if all keys match exactly the keys in the source object?!
korzo
@korzo
Sep 19 2017 13:56
@Blauelf Yeah, that's much better.
but I was trying to fix only inner loop from my previous snippet
Blauelf
@Blauelf
Sep 19 2017 13:56
@korzo Using break without a loop makes it even more goto-like. I think I get an idea why most people avoid continue/break.
korzo
@korzo
Sep 19 2017 14:00
@Blauelf Sure, I doubt I ever used labeled block
But I think using continue/break (without label) inside loop is ok,
can't think of a simple aproach to this? can someone give me a little "light" on this kata?
Stephen James
@sjames1958gm
Sep 19 2017 15:08
@tiagocorreiaalmeida Looping for length of the string and shift (use slice) and compare
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 15:09
confusing how im gonna control the slice start and end
Stephen James
@sjames1958gm
Sep 19 2017 15:10
@tiagocorreiaalmeida Just slice off last character and add to front.
first.slice(-1) + first.slice(0, first.length - 1)
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 15:12
was looking to the exercise in the wrong way thanks @sjames1958gm will help alot
CamperBot
@camperbot
Sep 19 2017 15:12
tiagocorreiaalmeida sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8469 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Blauelf
@Blauelf
Sep 19 2017 15:13
Guess my if (first.slice(first.length-i) === second.slice(0, i) && first.slice(0, first.length-i) === second.slice(i)) { is way too complicated.
Tai Jones
@taiJones00
Sep 19 2017 15:24
12
function whatIsInAName(collection, source) {
3
  // What's in a name?
4
  var arr = [];
5
  // Only change code below this line
6
  //source loop outside collection loop. until the values of source are used up, go through all of collection
7
  for (var i = 0; i < source.length; i++)
8
    {
9
      for (var j = 0; j < collection.length; j++)
10
      {
11
        if (source[i] == collection[j])
12
        {
13
          arr.push(source[i]);     
14
        }
15
      }
16
    }
17

18
  // Only change code above this line
19
  return arr;
20
}
2122
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
23
Why isn't this working
Diego Mayer
@Chrono79
Sep 19 2017 15:29
@taiJones00 source isn't an array
Blauelf
@Blauelf
Sep 19 2017 15:30
@taiJones00 source is not an array. Use the keys/property names of source in an inner loop. And push collection[j] only if all the properties of source can be found in collection[j] with matching values.
Tai Jones
@taiJones00
Sep 19 2017 15:30
i'm just refrencing where I am in the collection with [i] and [j]
Fredrik Strand Oseberg
@FredrikOseberg
Sep 19 2017 15:42
I’m working on an application with React. I have a long list of data that when clicked is added to application state held in the root App component. Whenever something is clicked lower down on this list, React triggers a re-render and scrolls to the top of the page. Is there any way to disable the scrolling to the top of the page?
Tai Jones
@taiJones00
Sep 19 2017 15:56
I don't get it
I didn't mean it was an array. Can't I just acces an index like this[]
with anything
Jan Shah
@JanShah
Sep 19 2017 15:57
@taiJones00 you're looping through source like it is an array
@taiJones00 it won't return a length
Tai Jones
@taiJones00
Sep 19 2017 15:57
so don't loop through source at all?
Jan Shah
@JanShah
Sep 19 2017 15:59
@taiJones00 no. source is an object, you can use hasOwnProperty to see if the object contains the key you're looking for
collection[j] is also an object, you have key, value pairs that you access by referencing the key
let obj = {key:'value'}
obj.hasOwnProperty('key') //returns true
Kelechi Chinaka
@ke1echi
Sep 19 2017 16:03
hi guys :wave:
i think this kata tests are wrong
my code passes all sample test and fails all random test
function incrementer(num) {
  let arr = [];
  for (let i = 0; i < num.length; i++) {
    num[i] = (num[i] + i+1)+'';
    (num[i].length > 1) ? arr.push(+num[i].slice(-1)) : arr.push(+num[i]);
  }
  return arr;
}
here my code
Tai Jones
@taiJones00
Sep 19 2017 16:04
ohhhhh
I can't loop through collection eitehr can I
mstellaluna
@mstellaluna
Sep 19 2017 16:05
@kelechy ask in the main room https://gitter.im/FreeCodeCamp/FreeCodeCamp they frequently do katas from codewars
they are discussing one now I believe
linkin-park
@linkin-park
Sep 19 2017 16:06
katas dont do anything in real life :fire:
they are joke1
Jason Luboff
@JLuboff
Sep 19 2017 16:08
Katas can be good practice
Jan Shah
@JanShah
Sep 19 2017 16:10
@kelechy my version passes both
Diego Mayer
@Chrono79
Sep 19 2017 16:10
@kelechy mine too
Jason Luboff
@JLuboff
Sep 19 2017 16:14
I have a working one as well
Nice one liner
Jan Shah
@JanShah
Sep 19 2017 16:16
@JLuboff whats your id on there?
I see it
Jason Luboff
@JLuboff
Sep 19 2017 16:16
@JanShah Same as here
Jan Shah
@JanShah
Sep 19 2017 16:17
I'm just under yours, centropy
Jason Luboff
@JLuboff
Sep 19 2017 16:18
I don't even know how to navigate the social aspect of CW lol
Jan Shah
@JanShah
Sep 19 2017 16:19
once you have a solution, you can view other solutions to see how everyone did it
Diego Mayer
@Chrono79
Sep 19 2017 16:19
@kelechy your problem is you're modifying the original array
Jan Shah
@JanShah
Sep 19 2017 16:19
@JLuboff
Jason Luboff
@JLuboff
Sep 19 2017 16:19
Ah.
linkin-park
@linkin-park
Sep 19 2017 16:19
if i really want to have some good foo , top coder
Diego Mayer
@Chrono79
Sep 19 2017 16:20
:wave:
later
Jason Luboff
@JLuboff
Sep 19 2017 16:20
@JanShah I wouldn't of thought to use %10 to handle the single digit return. Makes sense though
Jan Shah
@JanShah
Sep 19 2017 16:21
it was when I was refactoring, trying to bring it down from 20 lines :)
jk
it was about 10 :)
Jason Luboff
@JLuboff
Sep 19 2017 16:22
My solution is kind of wonky since I convert the number to a string to slice, then convert it back to a number lol
Jan Shah
@JanShah
Sep 19 2017 16:23
I did use that in one of my variations in the return string
刘国钧
@liuguojin2017
Sep 19 2017 16:24

var arrs = [];
function chunk(arr, size) {
// 请把你的代码写在这里

for(var i=1;i<=Math.ceil(arr.length/size);i++){
var a = arr.slice((i-1)size,sizei);
arrs[i-1]=a;
}
return arrs;
}
chunk(["a", "b", "c", "d"], 2);

why?
tell me why?
Anton Shapovalov
@remixedrewired
Sep 19 2017 16:38
Guyz, hello. I need help with implemention the remove method in dual linked list.
image.png
刘国钧
@liuguojin2017
Sep 19 2017 16:40
hello, I need help

Chunky Monkey
var arrs = [];
function chunk(arr, size) {
// 请把你的代码写在这里

for(var i=1;i<=Math.ceil(arr.length/size);i++){
var a = arr.slice((i-1)size,sizei);
arrs[i-1]=a;
}
return arrs;
}
chunk(["a", "b", "c", "d"], 2);

/tell me why/
Anton Shapovalov
@remixedrewired
Sep 19 2017 16:46
what why?
刘国钧
@liuguojin2017
Sep 19 2017 16:47
Fail to pass customs
Chunky Monkey
Chunky Monkey
chunk([0, 1, 2, 3, 4, 5], 4)
Fail to pass customs
linkin-park
@linkin-park
Sep 19 2017 16:48
@liuguojin2017 hi
刘国钧
@liuguojin2017
Sep 19 2017 16:48
hi
linkin-park
@linkin-park
Sep 19 2017 16:49
@liuguojin2017 when you guys going to start your own FCC ?
there is baidu after google :/
刘国钧
@liuguojin2017
Sep 19 2017 16:49
I KNOW
but why
linkin-park
@linkin-park
Sep 19 2017 16:50
dont take my wrong its just a question
curious
刘国钧
@liuguojin2017
Sep 19 2017 16:50

Chunky Monkey
var arrs = [];
function chunk(arr, size) {
// 请把你的代码写在这里

for(var i=1;i<=Math.ceil(arr.length/size);i++){
var a = arr.slice((i-1)size,sizei);
arrs[i-1]=a;
}
return arrs;
}
chunk([0, 1, 2, 3, 4, 5], 4) //?here,why?

@linkin-park
Joel Y.
@zapcannon99
Sep 19 2017 16:54
var a = arr.slice((i-1)size,sizei); What's sizei?
mstellaluna
@mstellaluna
Sep 19 2017 16:54
@linkin-park Please be respectful of your other campers. Review our code of conduct at https://www.freecodecamp.org/code-of-conduct/
刘国钧
@liuguojin2017
Sep 19 2017 16:54
size*i
Diego Mayer
@Chrono79
Sep 19 2017 16:54
@zapcannon99 unformatted code
var arrs = [];
function chunk(arr, size) {
  // 请把你的代码写在这里

   for(var i=1;i<=Math.ceil(arr.length/size);i++){
    var a = arr.slice((i-1)*size,size*i);
    arrs[i-1]=a;
   }
  return arrs;
}
刘国钧
@liuguojin2017
Sep 19 2017 16:55
var arrs = [];
function chunk(arr, size) {
// 请把你的代码写在这里
for(var i=1;i<=Math.ceil(arr.length/size);i++){
var a = arr.slice((i-1)*size,size*i);
arrs[i-1]=a;
}
return arrs;
}
chunk([0, 1, 2, 3, 4, 5], 4) //?here,why?
Joel Y.
@zapcannon99
Sep 19 2017 16:55
ah there we go
@Chrono79 gotcha
Diego Mayer
@Chrono79
Sep 19 2017 16:55
Don't use globals @liuguojin2017 they keep their values between tests
piteto
@piteto
Sep 19 2017 16:55

@liuguojin2017 put the arrs variable inside the function:

function chunk(arr, size) {
  var arrs = [];

  for (var i = 1; i <= Math.ceil(arr.length / size); i++) {
    var a = arr.slice((i - 1) * size, size * i);
    arrs[i - 1] = a;
  }
  return arrs;
}
chunk([0, 1, 2, 3, 4, 5], 4);

And make sure your function name matches what's being called.

Current exercises use chunkArrayInGroups()
Diego Mayer
@Chrono79
Sep 19 2017 16:56
@piteto maybe not in the chinese FCC
linkin-park
@linkin-park
Sep 19 2017 16:56
@mstellaluna hi well did i do anything wrong ? its just asking
Diego Mayer
@Chrono79
Sep 19 2017 16:56
has happened before
刘国钧
@liuguojin2017
Sep 19 2017 16:56
I am very so sorry ,my English is very poor
linkin-park
@linkin-park
Sep 19 2017 16:57
thats fine @liuguojin2017
刘国钧
@liuguojin2017
Sep 19 2017 16:57
@piteto thank you!
CamperBot
@camperbot
Sep 19 2017 16:57
liuguojin2017 sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 123 | @piteto |http://www.freecodecamp.com/piteto
刘国钧
@liuguojin2017
Sep 19 2017 16:58
Why is it possible to include variables in a function?
linkin-park
@linkin-park
Sep 19 2017 16:59
we didnt get you @liuguojin2017
Joel Y.
@zapcannon99
Sep 19 2017 16:59
The location you place the variable in determines what is called the scope of a variable
piteto
@piteto
Sep 19 2017 17:00
@liuguojin2017 It is a requirement for free code camp challenges only.
I'm sorry my chinese is so poor :)
linkin-park
@linkin-park
Sep 19 2017 17:01
@liuguojin2017 if you dont ask a question that other campers understand , probably they start reasoning with what they might think about your question :/
刘国钧
@liuguojin2017
Sep 19 2017 17:04
It's late at night. Good night! Continue tomorrow
linkin-park
@linkin-park
Sep 19 2017 17:06
sure !
Anton Shapovalov
@remixedrewired
Sep 19 2017 17:15
can some1 help me with my question? :(
Jason Luboff
@JLuboff
Sep 19 2017 17:15
@remixedrewired Its always best to post your code with your questions..
Anton Shapovalov
@remixedrewired
Sep 19 2017 17:19
@JLuboff i did it above
I have problem with implementaion of remove method

var Node = function(data, prev) {
  this.data = data;
  this.prev = prev;
  this.next = null;
};
var DoublyLinkedList = function() {
  this.head = null;
  this.tail = null;
  this.length = 0;

  this.add = function(element){
    var node = new Node(element, this.tail);

    if(this.length > 0){
      this.tail.next = node;
      node.prev = this.tail;
      this.tail = node;
    } else {
      this.head = node;
      this.tail = node;
    }
    this.length++;
    return node;
  };


};
linkin-park
@linkin-park
Sep 19 2017 17:37
i'm noob in DS
linkin-park
@linkin-park
Sep 19 2017 17:44
how are you removing node @remixedrewired
let it be always [X|Xs]= L :)
Anton Shapovalov
@remixedrewired
Sep 19 2017 17:48
:D
linkin-park
@linkin-park
Sep 19 2017 17:50
i have no clue why you have used this , are you binding with any of the fun Node ?
this is curse in js
Anton Shapovalov
@remixedrewired
Sep 19 2017 17:57
@linkin-park coz DoublyLinkedLis is a constructor function
Bryan Warman
@bwarman
Sep 19 2017 17:59
Is there a way to attach a scroll event to individual elements to run a function when an element hits a certain scroll height? I know how to do it for the window but I want to do it individually for each item in an grid layout.
So when somebody scrolls to a certain position the items can come in sequentially as they continue to scroll
linkin-park
@linkin-park
Sep 19 2017 18:06
i;m very bad in understanding @remixedrewired well can you explain your add elements more then 1 element
@bwarman hi is it different for window / grid ?
Pethaf
@Pethaf
Sep 19 2017 18:28
Ok. Why doesn't this work?
let data = { { name : "Paul O'Shannessy", avatar_url: "https://avatars.githubusercontent.com/u/8445?v=3", company: "Facebook" }, { name: "Ben Alpert", avatar_url: "https://avatars.githubusercontent.com/u/6820?v=3", company: "Facebook" }, };
Jason Luboff
@JLuboff
Sep 19 2017 18:28
@Pethaf It should be an array of objects, not objects within an object unless you give each object a key
Pethaf
@Pethaf
Sep 19 2017 18:30
I see now.
It should be an array of objects.
Jason Luboff
@JLuboff
Sep 19 2017 18:30
Yes
Pethaf
@Pethaf
Sep 19 2017 18:30
I really need to get a better monitor.
Kelechi Chinaka
@ke1echi
Sep 19 2017 18:34
thanks @Chrono79 ... it was not stated in the description
CamperBot
@camperbot
Sep 19 2017 18:34
kelechy sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4541 | @chrono79 |http://www.freecodecamp.com/chrono79
Kelechi Chinaka
@ke1echi
Sep 19 2017 18:34
:wave: @JLuboff
Jason Luboff
@JLuboff
Sep 19 2017 18:34
:wave:
Kelechi Chinaka
@ke1echi
Sep 19 2017 18:41
hope the projects are going well @JLuboff
Jason Luboff
@JLuboff
Sep 19 2017 18:41
Ya, still working on my Game (book) trading app
Kelechi Chinaka
@ke1echi
Sep 19 2017 18:43
cool
i hope to get to that level someday :smile:
Jason Luboff
@JLuboff
Sep 19 2017 18:44
Just takes time :D Not that I'm great at it or anything lol
linkin-park
@linkin-park
Sep 19 2017 18:49
i love games :) when can i see your game book ?
Jason Luboff
@JLuboff
Sep 19 2017 18:49
Whenever I finish it lol. I'd say I probably have a week to two before its done
linkin-park
@linkin-park
Sep 19 2017 18:50
what games you cover ? how this book is all about
is it for pro / beginner ?
Jason Luboff
@JLuboff
Sep 19 2017 18:50
It's this project: https://www.freecodecamp.org/challenges/manage-a-book-trading-club but instead of books, I'm doing it with games. Its just meant for trading among individuals
Christopher
@bradley1492
Sep 19 2017 18:52
This message was deleted

Hey,
I am still figuring out the https://www.freecodecamp.org/challenges/wherefore-art-thou challenge. Now I stumbled upon this thread in which the guy solves the challenge with the filter method. Heres his code:

function whatIsInAName(collection, source) {
  var properties = Object.keys(source);
  var result;

  var arr = collection.filter(function(item) {
    for(var i = 0; i < properties.length; i++) {
      if(item.hasOwnProperty(properties[i]) && item[properties[i]] == source[properties[i]]) {
        result = true;
      } else {
        result = false;
      }
    }

    return result;
  });

  return arr;
}

And then this is my code:


function whatIsInAName(collection, source) {
  var arr = [];
  var sourceKey = Object.keys(source);
  var sourceValues = Object.values(source);

  for(var i=0; i<collection.length; i++){
    for(var j=0; j<sourceKey.length; j++){     
      if(collection[i][sourceKey[j]] == source[sourceKey[j]] && collection[i].hasOwnProperty(sourceKey[j])){
        arr.push(collection[i]);

    }//end for 2  
  }//end for 1
  return arr;
}//end function
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });

I just can't see the difference.
I mean yes he is using the filter method and hence not using a nested for loop approach.
But to me it seems we have exactly the same logic going on in the if statement.
Why isn't his logic failing with the 3rd and the fourth test?

linkin-park
@linkin-park
Sep 19 2017 18:56
you should be joking @JLuboff
Jason Luboff
@JLuboff
Sep 19 2017 18:57
@linkin-park ...?
linkin-park
@linkin-park
Sep 19 2017 18:59
good
i thought you were writng a game book :/
Jason Luboff
@JLuboff
Sep 19 2017 19:01
Nope
linkin-park
@linkin-park
Sep 19 2017 19:02
dyna web app is fun :) cool FCC
what backend i need to do this todo app ?
linkin-park
@linkin-park
Sep 19 2017 19:08
gud luck
Jason Luboff
@JLuboff
Sep 19 2017 19:09
Todo app? The dynamic web apps are built on NodeJS as the backend
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 19:41
@JLuboff are you used to github?still struggle a bit with it
Jason Luboff
@JLuboff
Sep 19 2017 19:42
@tiagocorreiaalmeida In what regard? I know the basics I guess
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 19:44
Was thinking of creating a repo and updated some files every day to the same repo
after creating the repo and push the first files in the next day if I push only the new les to the repo it "appends" them right?
kinda of idea to be active there and to start to get used to it
Jason Luboff
@JLuboff
Sep 19 2017 19:46
New files as in not modified files? Yes, it will add them to the repo. Modified files will be updated to current if you add them. If file has not been changed, then it does not get changed with the push
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 19:47
nah its just new everyday big thanks probbly simple lets see how I make it out
Jason Luboff
@JLuboff
Sep 19 2017 19:47
You can view past versions too
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 19:48
cool if I need any help will come here thanks mate
Jason Luboff
@JLuboff
Sep 19 2017 19:48
No problem
aRtoo
@artoodeeto
Sep 19 2017 19:53
hi guys question. i need help. on this code about the heaps algorithm. i called the function inside the for loop and theres if statement inside the for loop. my question is when it goes inside the loop then calls the generate(n-1) will it exit the loop or change the value of n every time it loops while if statement is being executed? im confuse bros. need help. im trying to trace it on paper and im always stuck on that part i dont know which is to move. thnaks.
function generate(n) {
    if(n===1 && !regex.test(str.join(''))) {
      check.push(str.join(''));
    } else {
      for(var i=0; i<n; i++) {
        generate(n-1);
        if(n % 2 === 0 ) {
          swaper(i,n-1);
        } else {
          swaper(0,n-1);
        }
      }
    }
  }
  generate(3);
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 20:21
@JLuboff
how can I remove those?since those are not the repositoray location
image.png
since I can't add the correct one since it says allready has one
solved :D
Jason Luboff
@JLuboff
Sep 19 2017 20:23
Alright then lol
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 20:24
confusing thing
Jason Luboff
@JLuboff
Sep 19 2017 20:24
I think in general you can just remove the git folder, then redo the git init, add the git remote, etc
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 20:24
got it working niceee, so tomorrow all I have to do is add then commit and pus hit right?
Jason Luboff
@JLuboff
Sep 19 2017 20:24
add, commit, push
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 20:25
great thanks mate have a rest a of a good day
Jason Luboff
@JLuboff
Sep 19 2017 20:25
You too
monkeyfingerz
@monkeyfingerz
Sep 19 2017 20:40

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!

  for(var i = 0 ; i< arr2.length ; i ++ ){
       for(var j = 0 ; j<arr1.length ; j++){
         if(arr1[i][1] === arr2[j][1]){
           arr1[i][0] =arr2[j][0] + arr1[i][0];
arr2.splice(arr2[j],1);
         } 
       }

    }


  return arr2;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
why isn't my splice working?
Jason Luboff
@JLuboff
Sep 19 2017 20:44
@monkeyfingerz Shouldn't the first parameter for splice be the beginning index?
Joel Y.
@zapcannon99
Sep 19 2017 20:45
@JLuboff Should be
monkeyfingerz
@monkeyfingerz
Sep 19 2017 20:46
ok ok yeah that makes complete sense but why when i replace the first parameter with var j it still returns the same error

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!

  for(var i = 0 ; i< arr2.length ; i ++ ){
       for(var j = 0 ; j<arr1.length ; j++){
         if(arr1[i][1] === arr2[j][1]){
           arr1[i][0] =arr2[j][0] + arr1[i][0];
arr2.splice(j,1);
         } 
       }

    }


  return arr2;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
Joel Y.
@zapcannon99
Sep 19 2017 20:48
@monkeyfingerz what error is that?
Jason Luboff
@JLuboff
Sep 19 2017 20:48
I'm seeing an arr2[j] is undefined error, not a splice error
monkeyfingerz
@monkeyfingerz
Sep 19 2017 20:49
type error cannot read property of '1' of undefined
Jason Luboff
@JLuboff
Sep 19 2017 20:49
For some reason at index 3, its not able to read from the second array
monkeyfingerz
@monkeyfingerz
Sep 19 2017 20:50
hmmm
it should be index 2
Jason Luboff
@JLuboff
Sep 19 2017 20:50
@monkeyfingerz Ok I got some where
monkeyfingerz
@monkeyfingerz
Sep 19 2017 20:50
ok
where are you
Jason Luboff
@JLuboff
Sep 19 2017 20:51
Switch your if statement.. from if(arr1[i][1] === arr2[j][1]){ to if(arr1[j][1] === arr2[i][1]){
I don't think its getting the right answer, but its doing more at least lol
monkeyfingerz
@monkeyfingerz
Sep 19 2017 20:52
thats what i needed thanks @JLuboff
CamperBot
@camperbot
Sep 19 2017 20:52
monkeyfingerz sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2203 | @jluboff |http://www.freecodecamp.com/jluboff
Marc
@MWBauer
Sep 19 2017 21:03
Hey everyone!
I'm so close to figuring out the Falsy Bouncer.
I just need to figure out how to incorporate NaN.
function bouncer(arr) {
  var newArray = arr.filter(function(value){return value != "" && value != false && value != null && value != 0 && value != undefined;});
  return newArray;
}
Joel Y.
@zapcannon99
Sep 19 2017 21:09
Isn't NaN another keyword value?
I guess not, but there is a function to detect NaN though
Check the section "Testing against NaN"
monkeyfingerz
@monkeyfingerz
Sep 19 2017 21:11

function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!

  for(var i = 0 ; i< arr2.length ; i ++ ){
       for(var j = 0 ; j<arr1.length ; j++){
         if(arr1[j][1] === arr2[i][1]){
           arr1[i][0] =arr2[j][0] + arr1[i][0];
arr2.splice(j,1);

         } 
       }
         }
for(var k = 0; k< arr2.length; k++){
  arr1.push(arr2[k]);
}

  return arr1.sort(function(a,b){
    if(a[1] >b[1]){
      return 1;
    }else{
      return -1;
    }
  });
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
why isn't my nested for loop going checking against my primary loop. IF you run this code hair pin is still in the final array twice
Joel Y.
@zapcannon99
Sep 19 2017 21:30

@monkeyfingerz

I think the main issue is that you are splicing with the index j, rather than i when splicing with arr2.splice(j,1);. You are traversing the arr2 with i as shown in the first for loop for(var i = 0 ; i< arr2.length ; i ++ ){.

Keep in mind though that splice alters the original array, rather than the returning a new array, so it will mess up indexing in a forloop if you're not careful.

kumquatfelafel
@kumquatfelafel
Sep 19 2017 21:32
@monkeyfingerz have to go right now, so don't have time to look at, but added a bunch of console.logs to replit and may be able find on own. https://repl.it/LU2v/3
monkeyfingerz
@monkeyfingerz
Sep 19 2017 21:41
function Thanks (@zapcannon99 and @kumquatfelafel){
CamperBot
@camperbot
Sep 19 2017 21:41
monkeyfingerz sends brownie points to @zapcannon99 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 628 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 336 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
monkeyfingerz
@monkeyfingerz
Sep 19 2017 21:42
console.log("thank you");}
Stephen James
@sjames1958gm
Sep 19 2017 21:42
@MWBauer value === value is true only if value is not NaN
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 21:47
sorry im always a bit I dont know.. with algorithms
I have an array of numbers and it contains odd and even numbers I need to sort the odd and keep the even on their place, what's the smarter way to keep them on their position?I allready did something like this can't remember it sadly
Joel Y.
@zapcannon99
Sep 19 2017 21:54

Don't be sorry. It's a learning process.

I'm a bit confused as to what you want. Do you want to replace all the elements that are odd with and empty string? Or are you looking to reduce the length of the array so that the relative positions of even values are there?

Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 21:54

"You have an array of numbers.
Your task is to sort ascending odd numbers but even numbers must be on their places.

Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it."

Example

sortArray([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4]
Joel Y.
@zapcannon99
Sep 19 2017 22:00
Hmmm
My gut reaction would be to go through each each element in a for loop and put all the odd numbers in a separate array. Than sort that array. In place of every array is some symbol, which ever you want. Go back through the original array and feed the sorted array of odd numbers into the old array, replacing each symbol that you left behind. I think that should do the trick.
Yes this'll require 2 for loops, but they are not nested.
Tiago Correia
@tiagocorreiaalmeida
Sep 19 2017 22:01
sounds like a good idea trade like a number for something else on every odd number sort them outisde bring them back in probably that's how I would do it thanks
Joel Y.
@zapcannon99
Sep 19 2017 22:03
gl
surferpilgrim
@surferpilgrim
Sep 19 2017 22:47

if I have

var arr=[dog,bird,cat,tree,ship];

and I want

return arr[1,2,4]
//returns [bird,cat,ship]
Joel Y.
@zapcannon99
Sep 19 2017 23:18
?
surferpilgrim
@surferpilgrim
Sep 19 2017 23:20
I want to return an array based on multiple indices of that array
Joel Y.
@zapcannon99
Sep 19 2017 23:24
dunno if you can do arr[1,2,4]. It only looks at the last thing it seems
it being arr[1,2,4] == "ship"
surferpilgrim
@surferpilgrim
Sep 19 2017 23:24
@zapcannon99 is there a method where you can?
Joel Y.
@zapcannon99
Sep 19 2017 23:24
i mean you could make a function
surferpilgrim
@surferpilgrim
Sep 19 2017 23:25
@zapcannon99 Im a try that
pahosler
@pahosler
Sep 19 2017 23:25
@tiagocorreiaalmeida I did it in a weird way...
const isOdd =(num)=> (
  num % 2 === 1
)
const isEven = (num)=> (
  num %2 === 0
 )

array = [0,3,1,6,8,5,2,7];
evens = array.map((element)=>{
  if(isEven(element)){
    return element
  }else{
    return'o'
  }
})
odds = array.map((element) =>{
  if(isOdd(element)){ return element
  }else{
    return 'e'
  }
})

odds.forEach((element) => odds.splice(odds.indexOf('e'),1))
odds.sort()
evens.forEach((element) =>{
  if(element === 'o') {
    let num = odds.shift()
    evens.splice(evens.indexOf('o'),1,num)
  }
})

console.log('what are the odds',evens)
Joel Y.
@zapcannon99
Sep 19 2017 23:29
@surferpilgrim
Something like this maybe
function getStuff(original, elementsIWant) {
 var resultArr = [];
 for(var k = 0; k < elementsIWant.length; k++){
  resultArr.push(original[elementsIWant[k]]);
 }
return resultArr;
}
both parameters are arrays
Moisés Man
@moigithub
Sep 19 2017 23:38
const isOdd =(num)=> (
  num % 2 === 1
)
const isEven = (num)=> (
  num %2 === 0
 )

array = [5,3,2,8,1,4];
mapped = array.map(n=> isOdd(n)?"o":"e");  
odds = array.filter(isOdd).sort((a,b)=>a-b);
evens = array.filter(isEven);
o=0; e=0;
result= mapped.map((n)=>n=="o"?odds[o++]: evens[e++]);
console.log('what are the odds', result);
@pahosler
pahosler
@pahosler
Sep 19 2017 23:44
@moigithub much nicer :D
Diego Mayer
@Chrono79
Sep 19 2017 23:55
function sortArray(array) {
  var arr = array.filter(e=>e%2).sort((a,b)=>a-b);
  return array.map((e,i)=> e%2 ? arr.shift() : e);
}
Same idea, one map less
surferpilgrim
@surferpilgrim
Sep 19 2017 23:59
you guys are cool