7th
Jul 2016
Brandon McMahan
@DocMcMahan
Jul 07 2016 00:00
@alexanderkopke th
clintonjohn
@clintonjohn
Jul 07 2016 00:00
What does => mean?
Kent Saeteurn
@sansae
Jul 07 2016 00:04
@jaredabel Thank you for your help
CamperBot
@camperbot
Jul 07 2016 00:04
sansae sends brownie points to @jaredabel :sparkles: :thumbsup: :sparkles:
llamatarianism
@llamatarianism
Jul 07 2016 00:04
@clintonjohn it's an anonymous function
x => x + 2 is shorthand for
function(x) { return x + 2; }
clintonjohn
@clintonjohn
Jul 07 2016 00:06
@llamatarianism thanks so much! It didn't come up in my google search
CamperBot
@camperbot
Jul 07 2016 00:06
clintonjohn sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
jeanelleyy
@jeanelleyy
Jul 07 2016 00:07
can someone help me? i can't seem to sift out the non alphanumerical characters. for some reason it only removed the forward slash
function palindrome(str) {
// Good luck!
str.replace(/[^a-z0-9]+/g,"");
return str;
}

palindrome("five|\_/|four");
Carlos
@valecarlos
Jul 07 2016 00:08
Hi all, i'm trying my hand at the front-end tutorials, and i'm stuck in the convert To Roman test, can anyone give me any hints please? -- Convert the given number into a roman numeral. convertToRoman(2) should return "II"...
Ian Arsenault
@ianarsenault
Jul 07 2016 00:08
I'm working on the 'Where do I belong' problem. It's somehow working for 5 of the 7. Can anyone point me in the right direction, or where I'm making a problem.
function getIndexToIns(arr, num) {
// Sort the array
var sortedArr = arr.sort();
// Loop through the array
for (var i =0; i< sortedArr.length; i++) {
// If num is less than/equal to index of sorted array - get index
if(num <= sortedArr[i]) {
return sortedArr.indexOf(sortedArr[i]);
}
}
}

getIndexToIns([3, 3, 5, 20], 5); // Getting - it should be 2
llamatarianism
@llamatarianism
Jul 07 2016 00:08
you're only replacing lowercase letters
Ian Arsenault
@ianarsenault
Jul 07 2016 00:08
llamatarianism
@llamatarianism
Jul 07 2016 00:08
not uppercase ones
@GorgonsMaze replace <= with <
Ian Arsenault
@ianarsenault
Jul 07 2016 00:10
Still getting the same problem
llamatarianism
@llamatarianism
Jul 07 2016 00:10
also, arr.indexOf(arr[i]) === i in most cases
so just return i
Ian Arsenault
@ianarsenault
Jul 07 2016 00:10
ok
llamatarianism
@llamatarianism
Jul 07 2016 00:10
in fact that was probably the issue wasn't it
Ian Arsenault
@ianarsenault
Jul 07 2016 00:10
Nah
Still the same problem
llamatarianism
@llamatarianism
Jul 07 2016 00:10
since that'll return the first index of the number, not i
Ian Arsenault
@ianarsenault
Jul 07 2016 00:11
One more is wrong now
llamatarianism
@llamatarianism
Jul 07 2016 00:11
actually sorry I'm wrong
change it back to <=
David Karchynski
@ekvel
Jul 07 2016 00:12
@jeanelleyy try to store a reversed string (look up split(), reverse(), and join() methods) and remove all non-alphanumerical characters using regex and then coompare the two strings (look up what W does in regexp)
llamatarianism
@llamatarianism
Jul 07 2016 00:12
looks like you're supposed to insert it before other occurrences, otherwise [3, 3, 5, 20] and 5 would return 3 rather than 2
so <= is the right choice
jeanelleyy
@jeanelleyy
Jul 07 2016 00:14
@ekvel ok thanks. I'll try that
CamperBot
@camperbot
Jul 07 2016 00:14
jeanelleyy sends brownie points to @ekvel :sparkles: :thumbsup: :sparkles:
Ian Arsenault
@ianarsenault
Jul 07 2016 00:15
@llamatarianism Yeah I thought that myself. I'm just kind of confused how it's returning the correct answer for 5 of them, but not these two.
// getIndexToIns([2, 5, 10], 15) should return 3.  This returns blank
// getIndexToIns([5, 3, 20, 3], 5) should return 2. I get 0

function getIndexToIns(arr, num) {
// Sort the array
var sortedArr = arr.sort();
// Loop through the array
for (var i =0; i< sortedArr.length; i++) {
// If num is less than/equal to index of sorted array - get index
if(num <= sortedArr[i]) {
return i;
}
}
}

getIndexToIns([3, 3, 5, 20], 5);
The rest of them work, but those two
llamatarianism
@llamatarianism
Jul 07 2016 00:17
OHHHH I remember!
the JS devs are constantly on cocaine, so sorting an array of numbers sorts them based on the ascii value of the strings representing them
so 20 comes before 3 or 5
you have to do this for it to work properly
arr.sort((a, b) => a - b)
Ian Arsenault
@ianarsenault
Jul 07 2016 00:18
lol how the hell was I supposed to figure that out.
Goddamn JS devs and their cocaine
llamatarianism
@llamatarianism
Jul 07 2016 00:19
to be fair it is in the documentation
but to be fairer
it's a goddamn stupid decision
Ian Arsenault
@ianarsenault
Jul 07 2016 00:19
Where is it in the documentation?
The Mozzila Docs?
llamatarianism
@llamatarianism
Jul 07 2016 00:20
yes
Ian Arsenault
@ianarsenault
Jul 07 2016 00:24
I'm trying to find what you're talking about as so I can better understand it , but I'm unsure where
arr.sort((a, b) => a - b) is in
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Which is the documentation they have in that problem
I'm probably going over it.
jeanelleyy
@jeanelleyy
Jul 07 2016 00:26
function palindrome(str) {
// Good luck!
var tempArr=str.split('').reverse().join('');
tempArr.replace(/\W/g,"");
return tempArr;
}

palindrome("five|\_/|four");
llamatarianism
@llamatarianism
Jul 07 2016 00:26
basically
if the callback to sort returns a positive number it swaps them
jeanelleyy
@jeanelleyy
Jul 07 2016 00:27
can someone help me remove the non alphanumerical characters
llamatarianism
@llamatarianism
Jul 07 2016 00:27
otherwise they stay in place
so if a > b then a - b > 0
so they'll get swapped
@jeanelleyy \w includes underscores, so \W does not match underscores. you need /\W|_/g to match non-word characters or underscores
jeanelleyy
@jeanelleyy
Jul 07 2016 00:30
@llamatarianism it doesn't work. the "|" and slashes are still there too
Ramya
@ramyakatakam
Jul 07 2016 00:33

function sumPrimes(num) {
var count=0,j=1,i=2,k;
var a=[0];
while(i<num)
{
j=1;
while(j<i)
{
if(i%j===0)
{

    }
j++;

}

a.push(i);
i++;
//return false;
}

// for(k=0;k<a.length;k++)
// count=count+a[k];
return a;
}

sumPrimes(10); why it is going to infinite loop at line 6 can anyone help me

Mia
@Psyconne
Jul 07 2016 00:33
Hello guys
llamatarianism
@llamatarianism
Jul 07 2016 00:33
wait I just saw
Ian Arsenault
@ianarsenault
Jul 07 2016 00:33

@llamatarianism Ok I get that now. Though the arr.sort you posted doesn't work in my code so I tried doing it as a function, which solved 1 more of them, but I'm still left with one last problem

function getIndexToIns(arr, num) {
// Sort the array
var sortedArr = arr.sort(function(a, b) {
return a -b;
});
// Loop through the array
for (var i =0; i< sortedArr.length; i++) {
// If num is less than/equal to index of sorted array - get index
if(num <= sortedArr[i]) {
return i;
}
}
}

/* This returns Blank */
getIndexToIns([2, 5, 10], 15);

Not sure why this one keeps coming in the console as blank

llamatarianism
@llamatarianism
Jul 07 2016 00:33
strings are immutable
Mia
@Psyconne
Jul 07 2016 00:33
Can someone help me with the 'Record Collection' ..
llamatarianism
@llamatarianism
Jul 07 2016 00:34
you have to reassign to them if you want to change them because they can't be changed in place
so this line:
tempArr.replace(/\W/g,"");
does nothing
@GorgonsMaze what if there aren't any numbers in the array that are greater than num?
because you only return inside the loop
jeanelleyy
@jeanelleyy
Jul 07 2016 00:36
@llamatarianism thank you! that worked
CamperBot
@camperbot
Jul 07 2016 00:36
jeanelleyy sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
Ian Arsenault
@ianarsenault
Jul 07 2016 00:37
@llamatarianism aHa.
Coy Sanders
@coymeetsworld
Jul 07 2016 00:38
what do you need help with on it @Psyconne ?
Nick Irvine
@irvin3
Jul 07 2016 00:39
I was hoping someone could help me a little with Wherefore art thou
my current code is '''
CamperBot
@camperbot
Jul 07 2016 00:39
:bulb: to format code use backticks!  more info
Nick Irvine
@irvin3
Jul 07 2016 00:39
'''
CamperBot
@camperbot
Jul 07 2016 00:39
:bulb: to format code use backticks!  more info
Nick Irvine
@irvin3
Jul 07 2016 00:40
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
var test = Object.keys(source);
var forL = [];
//var test1 = source.hasOwnProperty(test);
// Only change code below this line
for(var key in source){
var value  = source[key];
forL.push(value);
}
var xx = collection[1].hasOwnProperty(test);
// Only change code above this line

console.log(test);
console.log(forL);
console.log(xx);

}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
I just dont know how to compare key values
Ian Arsenault
@ianarsenault
Jul 07 2016 00:42
This message was deleted
CruftMaster
@CruftMaster
Jul 07 2016 00:48
hey guys, can anyone help with the "arguements optional" algorithm?
Mia
@Psyconne
Jul 07 2016 00:48
@coymeetsworld thank you, can we talk tomorrow, I am going to sleep
CamperBot
@camperbot
Jul 07 2016 00:48
psyconne sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1247 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Rachel Melville
@rjmelville
Jul 07 2016 00:50
Looking for help on 'Mutations' algorithm. Can't get the for loop to iterate through the characters of the 2nd element...
function mutation(arr) {
arr[1] = arr[1].toLowerCase().split("");
for (i = 0; i < arr[1].length; i++) {
if (arr[0].indexOf(arr[1][i]) === -1) {
return false;
}
else {
return true;
}
}
}

mutation(["hello", "hey"]);
Coy Sanders
@coymeetsworld
Jul 07 2016 00:50
sure @Psyconne, gd night
CruftMaster
@CruftMaster
Jul 07 2016 00:52
function addTogether() {

var args = Array.from(arguments);

for(i=0;i<args.length;i++){

if(isNaN(args[i])){
return ;
}
}

var singleVal = args.reduce(function(previousVal, singleVal) {
return previousVal + singleVal;
},0);

return singleVal;
}

addTogether(2,"f");
Coy Sanders
@coymeetsworld
Jul 07 2016 00:53
@rjmelville the reason is because the first iteration will always return something
but you don't want to do that, you want to go through each character of the string until you either reach the end or find a character that doesn't exist in the other string
Rachel Melville
@rjmelville
Jul 07 2016 00:54
@coymeetsworld oh! right.
Jacob Stewart
@JacobStewart1
Jul 07 2016 00:56

hey i'm having trouble on the check for palnidromes challenge my code is
function palindrome(str) {
// Good luck!
str.replace([/\w+//'']);
str.toLowerCase();
if (str.split('').reverse().join() == str) {
return true;
}
else {
return false;
}
}

palindrome("eye"); and it returns the false statements correctly but not any of the true any help would be appreciated

Rachel Melville
@rjmelville
Jul 07 2016 00:56
@coymeetsworld So that would require a different kind of loop, right?
yesungC
@yesungc
Jul 07 2016 00:56
Hello~ I've been working on the 'Record collection' over few hours. I need some help.
Coy Sanders
@coymeetsworld
Jul 07 2016 00:57
I think the loop is fine @rjmelville, just need to think about when you're returning true
yesungC
@yesungc
Jul 07 2016 00:57
Rachel Melville
@rjmelville
Jul 07 2016 00:57
@coymeetsworld Gotcha. Ok, I think I know what to do. Thanks for the help!
CamperBot
@camperbot
Jul 07 2016 00:57
rjmelville sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1248 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Ian Arsenault
@ianarsenault
Jul 07 2016 00:58
function getIndexToIns(arr, num) {
// Sort the array
var sortedArr = arr.sort(function(a, b) {
return a -b;
});

// Loop through the array
for (var i =0; i< sortedArr.length; i++) {
// If num is less than/equal to index of sorted array - get index
if(num <= sortedArr[i]) {
return i;
}

/* If num is greater than the last index of sorted array
- get last index + 1 */

}
}

getIndexToIns([2, 5, 10], 15);
Can anyone tell if my comment is what I'm trying to actually do when the num is greater than all the numbers in the array?
Coy Sanders
@coymeetsworld
Jul 07 2016 00:58
no problem, good luck @rjmelville
clintonjohn
@clintonjohn
Jul 07 2016 01:01
I'm on the algorithm challenge for finding the longest length string. My research suggests using .split is not a good practice. I've come across an elegant solution where the the author used this symbol: [o] and I wanted to research his solution more, but I haven't found out what [o] means
Moisés Man
@moigithub
Jul 07 2016 01:02
@clintonjohn if u post the whole code... would be easier
clintonjohn
@clintonjohn
Jul 07 2016 01:02
on
ok
goyalruchi90
@goyalruchi90
Jul 07 2016 01:02
@JacobStewart1 : use str.split('').reverse().join('')==str
Jacob Stewart
@JacobStewart1
Jul 07 2016 01:02
ok thank @goyalruchi90
CamperBot
@camperbot
Jul 07 2016 01:02
jacobstewart1 sends brownie points to @goyalruchi90 :sparkles: :thumbsup: :sparkles:
Moisés Man
@moigithub
Jul 07 2016 01:04
@JacobStewart1 replace and toLowerCase dont mutate the array.. but return a new array..
u need to reassign the value returned
also ur replace is not right replace requires 2 arguments.. check the documentation
clintonjohn
@clintonjohn
Jul 07 2016 01:04
.match(/\w+/g).sort().reverse()[0].length
with the string preceding
Oh now I see it is a zero within the brackets
Moisés Man
@moigithub
Jul 07 2016 01:05
@clintonjohn .match return an array of matches
soo the [0] is one index of that array (first element )
clintonjohn
@clintonjohn
Jul 07 2016 01:06
@moigithub thanks!!
CamperBot
@camperbot
Jul 07 2016 01:06
clintonjohn sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 1665 | @moigithub |http://www.freecodecamp.com/moigithub
clintonjohn
@clintonjohn
Jul 07 2016 01:07
@moigithub I thought is was a lower case alphabet letter "o" the way it appeared elsewhere
Moisés Man
@moigithub
Jul 07 2016 01:07
:)
GGvibes
@GGvibes
Jul 07 2016 01:15
i need some help here. stuck on "testing objects for properties"
This message was deleted
// Setup
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
}
else if (myObj.hasOwnProperty("pet")){
return myObj.pet;
}
else if (myObj.hasOwnProperty("bed")){
return myObj.bed;
}
else {
}
}

// Test your code by modifying these values
checkObj("gift");
goyalruchi90
@goyalruchi90
Jul 07 2016 01:16
try checkObj(myObj)
Joseph
@revisualize
Jul 07 2016 01:16
Why aren't you using the variable?
goyalruchi90
@goyalruchi90
Jul 07 2016 01:17
@GGvibes : try calling checkObj(myObj) .gift
Joseph
@revisualize
Jul 07 2016 01:17
No.
myObj.hasOwnProperty(checkProp);
goyalruchi90
@goyalruchi90
Jul 07 2016 01:17
ya
Joseph
@revisualize
Jul 07 2016 01:18
then you call the object property
goyalruchi90
@goyalruchi90
Jul 07 2016 01:20
GGvibes
@GGvibes
Jul 07 2016 01:20
ok thanks @revisualize and @goyalruchi90 . So after function do I put myObj.hasOwnProperty(checkProp) or just checkObj(myObj)
CamperBot
@camperbot
Jul 07 2016 01:20
ggvibes sends brownie points to @revisualize and @goyslee :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for goyslee
:star2: 1374 | @revisualize |http://www.freecodecamp.com/revisualize
Eden Coleman
@nede36
Jul 07 2016 01:31

Working on the lesson Factorialize a Number: I passed all the requirements but I just want to know if this is the proper method of doing so: function factorialize(num) {
if (num === 0) {
return 1;
}

// This is it! Recursion!!
return num * factorialize(num - 1);
}
factorialize(8);

goyalruchi90
@goyalruchi90
Jul 07 2016 01:35
:+1:
yes this is the way
Eden Coleman
@nede36
Jul 07 2016 01:36
Alright cool, I was just coming across a few resources that were mentioning that I could also use for loops
Just wanted to see if one way was preferred or better than the other
goyalruchi90
@goyalruchi90
Jul 07 2016 01:36
but recursion is always better than for loop
Eden Coleman
@nede36
Jul 07 2016 01:37
Awesome, that is all I needed to know
clintonjohn
@clintonjohn
Jul 07 2016 01:37
@moigithub I see you used the sort method to solve the longest string length algorithm. May I ask what led you to prefer this? I'm learning from asking this question
Since there are so many ways to do it
96street
@96street
Jul 07 2016 01:41
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
function diffArray(arr1, arr2) {
var newArr = [];
arr1 = arguments[0];
arr2 = arguments[1];
for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(!arr1.indexOf(j)) {
newArr.push(j);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Why doesn't this work?
Veronica
@veronicarbulu
Jul 07 2016 01:42

Hi all - I've hit a wall on the record collection exercise. This is the assignment:
Write a function which takes an id, a property (prop), and a value.

For the given id in collection:

If prop does not contain the key "tracks", then update or set the value for that incomplete prop.

If prop does not contain the key "tracks" before you update it, create an empty array before pushing a track to it.

If prop does contain the key "tracks" and its value is non-blank, then push the value onto the end of its existing tracks array.

If value is blank, delete that prop.

Always return the entire collection object.

I'm not sure I really understand the section where it asks that I create an empty array. Either way, I tried a few times but can't nail it. Any guidance is appreciated. Here are the different versions of the code I've tried:
OPTION 1 (I get 5 out of 6 with this one)
if (value === " ") {
delete collection[id][prop];
}

else if (prop !== "tracks") {
collection[id][prop] = { };
collection[id][prop] = value;

}
else if (prop === "tracks" && value !== " ") {
collection[id][prop].push(value);
}

OPTION 2 (I get 4 out of 6)

if (value === " "){
delete collection[id][prop];
}
else if (prop === "tracks" && value !== " ")
{
collection[id][prop].push(value);
}
else {
if (prop !== "tracks"){
collection[id][prop] = [ ];
collection[id][prop].push(value);
}
else {
collection[id][prop]=value;
}
}

OPTION 3 (I get 5 out of 6)

if (value === " "){
delete collection[id][prop];
}
else if (prop !== "tracks"){
collection[id][prop] = value;
}
else {
if (collection.hasOwnProperty(prop)) {
collection[id][prop] = [ ];
collection[id][prop].push(value);
}
else {
collection[id][prop].push(value);
}
}

OPTION 4 (I get 4 out of 6)
if (prop === "tracks" && value !== "") {
collection[id][prop].push(value);
}
else if (prop !== "tracks") {
collection[id][prop] = value;
}
else if (value === ""){
delete collection[id][prop];
}

Randy Goldsmith
@Dueldrawer8
Jul 07 2016 01:44
why arent the wiki links working for the challenges?
Diego
@disofu234
Jul 07 2016 01:47
make sure the link starts with htpps
*https
Ian Robbins
@ierobbins
Jul 07 2016 01:50
@96street You're pushing the index onto the new array, not the value at the index. You have the same problem with the condition in your if statement.
yesungC
@yesungc
Jul 07 2016 01:51
@veronicarbulu hey, I'm stuck on the same thing. At most have been getting 5/6.
Veronica
@veronicarbulu
Jul 07 2016 01:52
@yesungc yes, it's a tricky one
Damnme
@Damnme
Jul 07 2016 01:52
cannot assign to readonly property '0' of string 'I'm'
a[i][0] = a[i][0].toUpperCase(); a[i] is 'I'm'
96street
@96street
Jul 07 2016 01:52
So change 'j' to arr2[j]?
yesungC
@yesungc
Jul 07 2016 01:53
@veronicarbulu let me work at it a bit more and show you what I have so far... I did something wrong so the whole page reset. LOL starting again(might be for the better)
Veronica
@veronicarbulu
Jul 07 2016 01:53
@yesungc let's keep trying.
Diego Mayer
@Chrono79
Jul 07 2016 01:53
@veronicarbulu look again at your OPTION 3
if (collection.hasOwnProperty(prop)) { <- this should be collection[id].hasOwn...
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 01:54
Hey awesome peeps! So I'm working on the JavaScript problems "Record Collection" and I am kind of stumped
Veronica
@veronicarbulu
Jul 07 2016 01:54
@Chrono79 ok. I'll look at it closely, but I'm not sure what i'm missing
Diego Mayer
@Chrono79
Jul 07 2016 01:55
Veronica
@veronicarbulu
Jul 07 2016 01:55
@Chrono79 just saw it. Thanks! I'll try that!
CamperBot
@camperbot
Jul 07 2016 01:55
veronicarbulu sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1438 | @chrono79 |http://www.freecodecamp.com/chrono79
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 01:55
@veronicarbulu so we're stumped on the same problem
Veronica
@veronicarbulu
Jul 07 2016 01:56
@samfitz1 :worried:
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 01:56
seriously
the problem sucks hah
eliza khachatryan
@Elijbet
Jul 07 2016 01:56
Hello, can someone help me with the "profile lookup" assignment?
javascript
clintonjohn
@clintonjohn
Jul 07 2016 01:57
@goyalruchi90 I've done some research that indicates recursion and loops may hold varying advantage over one another based on the situation and goals, including depending on what programming language is used.
96street
@96street
Jul 07 2016 01:58

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

function diffArray(arr1, arr2) {
var newArr = [];
arr1 = arguments[0];
arr2 = arguments[1];
for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(!arr1.indexOf(arr2[j])) {
newArr.push(arr2[j]);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

still struggling on this any idea what's wrong? it returns [1, 1, 1, 1]

Veronica
@veronicarbulu
Jul 07 2016 01:59
@Chrono79 I tried that and still get 5 out of 6.
Ian Robbins
@ierobbins
Jul 07 2016 01:59
@96street Yeah, but your if condition should also check arr1[i] and compare it to arr2[j] and check if they're not equal.
goyalruchi90
@goyalruchi90
Jul 07 2016 01:59
@clintonjohn :but that was a simple factorization problem in which recurssion is better than using for loop
Diego Mayer
@Chrono79
Jul 07 2016 01:59

@samfitz1 @veronicarbulu Read these alternative instructions:
You are given a JSON object representing a part of your musical album collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.

Write a function which takes an album's id (like 2548), a property prop (like "artist" or "tracks"), and a value (like "Addicted to Love") to modify the data in this collection.

If prop isn't "tracks" and value isn't blank, update or set the value for that record album's property.

Your function must always return the entire collection object.

There are several rules for handling incomplete data:

If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.

If prop is "tracks" and value isn't blank, push the value onto the end of the album's existing tracks array.

If value is blank, delete that property from the album.

Veronica
@veronicarbulu
Jul 07 2016 02:00
@Chrono79 ok
96street
@96street
Jul 07 2016 02:00
@ierobbins yeah i know i'm just trying to get the first part of it, it should be returning 4 but it's not
clintonjohn
@clintonjohn
Jul 07 2016 02:00
@goyalruchi90 thanks. I didn't catch the context
CamperBot
@camperbot
Jul 07 2016 02:00
clintonjohn sends brownie points to @goyalruchi90 :sparkles: :thumbsup: :sparkles:
yesungC
@yesungc
Jul 07 2016 02:00
@veronicarbulu lol
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 02:00
@Chrono79 k
Diego Mayer
@Chrono79
Jul 07 2016 02:00
@veronicarbulu you should create the array if tracks doesn't exist, I think you're doing it the other way around
goyalruchi90
@goyalruchi90
Jul 07 2016 02:01
@96street : try (!arr2.indexOf(arr2[j])) also
Ian Robbins
@ierobbins
Jul 07 2016 02:01
@96street thats because its looping through all the values of arr2 and comparing it to the i value of arr1, so it checks 1 and 1. equal so it doesnt add, then 1 and 2, not equal so it adds and so on
yesungC
@yesungc
Jul 07 2016 02:03
@Chrono79 I think either way, she would end up getting the 2nd one wrong and 4th correct or vice-versa
96street
@96street
Jul 07 2016 02:05
i said push() it if it doesn't add? @ierobbins
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 02:05
@veronicarbulu did you figure it out?
Maria Trujillo
@mtruj013
Jul 07 2016 02:05
Hey guys. I'm looking for help on the Convert Celsius to Fahrenheit challenge. I can't seem to figure out how to give different values to convertToF at the same time . I'm sure it's something small I'm overlooking, anyone care to point it out?
96street
@96street
Jul 07 2016 02:06
That's just searching the same arr? @goyalruchi90
Or do you mean: (!arr2.indexOf(arr2[i]) ?
goyalruchi90
@goyalruchi90
Jul 07 2016 02:07
ya i meant the..sorry typo :P
96street
@96street
Jul 07 2016 02:07
That returns [1, 2, 3, 4, 5]
Diego Mayer
@Chrono79
Jul 07 2016 02:07
@veronicarbulu there is another problem with your code, empty string is "" not this " " (this is a space btw)
Ian Robbins
@ierobbins
Jul 07 2016 02:08
@96street Your code needs to take the value of arr1 at index i and FIRST check all the values of arr2. If arr[i] doesn't equal any of the elements of arr2, then you push onto new array
Josh
@joshweaver23
Jul 07 2016 02:08

working on make a person:

var Person = function(firstAndLast) {
var nameArr = firstAndLast.split(" ");
var firstName = nameArr[0];
var lastName = nameArr[1];
var fullName = firstAndLast;

return {
getFirstName:function() {
return firstName;
},
getLastName: function() {
return lastName;
},
getFullName: function() {
return fullName;
},
setFirstName: function(first) {
firstName = first;
},
setLastName: function(last) {
lastName = last;
},
setFullName: function(full) {
nameArr = full.split(" ");
firstName = nameArr[0];
lastName = nameArr[1];
fullName = full;
}
};
};

var bob = new Person('Bob Ross');
bob.getFullName();

bob instanceof Person returns false
bob.getFullName() does not work after bob.setFirstName("Haskell")
nor after bob.setLastName("Curry")

96street
@96street
Jul 07 2016 02:10
Isn't that what this is doing?: !arr2.indexOf(arr2[i]) | Checking if arr[i] doesn't exist in arr2? @ierobbins
yesungC
@yesungc
Jul 07 2016 02:10
@Chrono79 have you solved this one?
Diego Mayer
@Chrono79
Jul 07 2016 02:10
yes
Veronica
@veronicarbulu
Jul 07 2016 02:10
@samfitz1 not yet
yesungC
@yesungc
Jul 07 2016 02:11

if (value === ""){
delete collection[id][prop];
}

else if (prop !== "tracks" && value !==""){
collection[id][prop] = value;
}

else if (prop === "tracks" && collection[id][prop] === null){
collection[id][prop] = [];
collection[id][prop].push(value);}

else if(prop === "tracks" && value !==""){
collection[id][prop].push(value);
}

return collection;
}

this is what I have so far.
Diego Mayer
@Chrono79
Jul 07 2016 02:12
@veronicarbulu are you returning collection after the code you've pasted?
Ian Robbins
@ierobbins
Jul 07 2016 02:12
@96street the way you're doing it you're just going to push each element four times onto the new array because you push for each iteration of the second for loop
Veronica
@veronicarbulu
Jul 07 2016 02:12
@Chrono79 thanks. I thought "" and " " were the same. Good to know
CamperBot
@camperbot
Jul 07 2016 02:12
veronicarbulu sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: veronicarbulu already gave chrono79 points
Diego Mayer
@Chrono79
Jul 07 2016 02:12
@yesungc this test for property is not right: collection[id][prop] === null
It could be undefined, or you could use hasOwnProperty method
Note that you're chaining ifs, so no need for testing value again
96street
@96street
Jul 07 2016 02:13
what would you reccommend? @ierobbins
not sure how to go about the block inside the if statement
Veronica
@veronicarbulu
Jul 07 2016 02:13
@Chrono79 yes, i did return collection
@pk422
Jul 07 2016 02:13
@mtruj013 you just have to apply the formula for converting F to C, "celsius" being the input
Ian Robbins
@ierobbins
Jul 07 2016 02:15
@96street try a boolean variable. your if when your if condition is false you can change it and then push the element only if your boolean is true at the end of the loop. something along those lines
This message was deleted
yesungC
@yesungc
Jul 07 2016 02:17
@Chrono79 Can I ask you something? Is this how you create an empty array? collection[id][prop] = [];?
Diego Mayer
@Chrono79
Jul 07 2016 02:17
@yesungc yes
Josh
@joshweaver23
Jul 07 2016 02:18
@Chrono79 if you get a minute, mind checking out the code i posted?
Ian Robbins
@ierobbins
Jul 07 2016 02:18
I'm on the Record Collection problem and I keep getting the TypeError: Cannot read property 'hasOwnerProperty' of undefined. How do I fix this?
Diego Mayer
@Chrono79
Jul 07 2016 02:19
@ierobbins what are you doing?
Ian Robbins
@ierobbins
Jul 07 2016 02:19
how do i display my code to the screen? just copy and paste?
Diego Mayer
@Chrono79
Jul 07 2016 02:19
help format
CamperBot
@camperbot
Jul 07 2016 02:19

# Multi line Code

js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

 ⇦ Type 3 backticks, then press [enter ⏎]

# Single line Code

This an inline <paste code here> code formatting with a single backtick() at _start_ and _end_ around thecode.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

Abhisek Pattnaik
@abhisekp
Jul 07 2016 02:20

### Random Quiz 101-09

Q: What is the size of an IP address?
A. 64 bit
B. 32 bit
C. 16 bit
D. 128 bit
Diego Mayer
@Chrono79
Jul 07 2016 02:20
@joshweaver23 I see several problems in your code, let me see if I find some previous challenges so you see what is it
Ian Robbins
@ierobbins
Jul 07 2016 02:20

// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

if(value !== null){
if(collection.id.hasOwnProperty(prop)){
if(prop === "tracks"){
collection.id.prop.push(value);}
else{
collection.id.prop = value;}
}
if(!collection.id.hasOwnProperty(prop)){
if(prop === "tracks"){
collection.id.prop = [];
collection.id.prop.push(value);}
else{
collection.id.prop = value;}
}
}
else if(prop === "tracks"){
collection.id.prop.pop();}
else {delete collection.id.prop;}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

'''

CamperBot
@camperbot
Jul 07 2016 02:20
:bulb: to format code use backticks!  more info
goyalruchi90
@goyalruchi90
Jul 07 2016 02:20
128 bits
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 02:21
@ierobbins is that the solution?
goyalruchi90
@goyalruchi90
Jul 07 2016 02:21
@abhisekp : ivp6 : 128bits, ipv4 : 32 bits
bitgrower
@bitgrower
Jul 07 2016 02:21
@joshweaver23 while @Chrono79 is doing that, let me pop in and say you have return statements within a return statement ... doesn't make much sense ...
Ian Robbins
@ierobbins
Jul 07 2016 02:21
thats the code i typed to solve the problem
Abhisek Pattnaik
@abhisekp
Jul 07 2016 02:21
@goyalruchi90 :white_check_mark:
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 02:21
can you explain it to me? I can skype if necessary
96street
@96street
Jul 07 2016 02:22
I'll try what you said but also is this necessary?:
arr1 = arguments[0];
arr2 = arguments[1];
Diego Mayer
@Chrono79
Jul 07 2016 02:22
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 02:22
Because I'm seriously struggling on this prob
Abhisek Pattnaik
@abhisekp
Jul 07 2016 02:22

### Random Quiz 101-10

Q: Write a regex to match an IPv4 address.
Diego Mayer
@Chrono79
Jul 07 2016 02:23
@ierobbins you can't use dot notation with vars, value could be empty string not null
bitgrower
@bitgrower
Jul 07 2016 02:23
@ierobbins -- you got real close to formatting it right -- like @camperbot tried to tell ya ... you need to use the backtick key, not the apostrophe key -- you can use copy & paste
Josh
@joshweaver23
Jul 07 2016 02:23
@Chrono79 okay, I'll take a look
bitgrower
@bitgrower
Jul 07 2016 02:23
@96street --which problem are you working on ?
Josh
@joshweaver23
Jul 07 2016 02:24
@bitgrower I was using this (http://javascriptissexy.com/understand-javascript-closures-with-ease/) as a reference, and they return functions with returns...
bitgrower
@bitgrower
Jul 07 2016 02:24
@joshweaver23 but you don't need closures for that challenge ... at all ...
96street
@96street
Jul 07 2016 02:25
/Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.?

function diffArray(arr1, arr2) {
var newArr = [];
arr1 = arguments[0];
arr2 = arguments[1];
for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(!arr2.indexOf(arr2[i])) {
newArr.push(arr2[j]);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
@bitgrower
is the arguments necessary or nah?
bitgrower
@bitgrower
Jul 07 2016 02:25
pretty sure anywhere in the js challenges closures are used, you'll find it in the useful links ... :) arguments optional is the only one I can think of offhand that does ...
Josh
@joshweaver23
Jul 07 2016 02:26
@bitgrower the challenge links to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures in the assignment...
bitgrower
@bitgrower
Jul 07 2016 02:26
ah ... okay ... then I'm thinking of the wrong challenge, I guess ... can you link the challenge for me ? my apologies ...
Josh
@joshweaver23
Jul 07 2016 02:26
bitgrower
@bitgrower
Jul 07 2016 02:27
@96street I see absolutely no reason for referencing arguments whatsoever ...
96street
@96street
Jul 07 2016 02:27
so arr2 is automatically equal to the second argument in diffArr?
@bitgrower
ok i took it out all good
Diego Mayer
@Chrono79
Jul 07 2016 02:28
@ierobbins :point_up: 6 de julio de 2016 22:59
Maybe that helps
Abhisek Pattnaik
@abhisekp
Jul 07 2016 02:28

## Closure

These are nice references
bitgrower
@bitgrower
Jul 07 2016 02:28
however, since there is futzing with the length of the arrays within the loops, you'd need to capture the original length of the arrays in separate variables ... as arr1.length could change when the loop gets re-evaluated ...
96street
@96street
Jul 07 2016 02:29
Here i'm trying to say: if an object from the first array is not in the 2nd array, push it to newArr
function diffArray(arr1, arr2) {
var newArr = [];

for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(!arr2.indexOf(arr2[i])) {
newArr.push(arr2[j]);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
but it's returning [1, 2, 3 , 4, 5]
Diego Mayer
@Chrono79
Jul 07 2016 02:30
@96street indexOf "false" value is -1, if you use !arr2.indexOf(arr2[i]) that only evaluates 0 as false
Stefan Bekirov
@bekir0v
Jul 07 2016 02:31
Hi
Anybody to Explain me what is wrong here
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line

myStorage.car.inside["glove box"];
96street
@96street
Jul 07 2016 02:31
@Chrono79 how does it only evaluate 0 to false?
Michael R
@Myst3420
Jul 07 2016 02:31
for (var i = size; i <= arr.length; i + size) {
var cutArr = arr.slice(x, y);
finalArr.push(cutArr);
x += 2;
y += 2;
}
Diego Mayer
@Chrono79
Jul 07 2016 02:32
@bekir0v set myStorage.car.inside["glove box"] to var gloveBoxContents
bitgrower
@bitgrower
Jul 07 2016 02:32
just part of the language definition, @96street
Diego Mayer
@Chrono79
Jul 07 2016 02:32
@96street the falsy value for numbers is 0 not -1
Michael R
@Myst3420
Jul 07 2016 02:32
Can someone explain why the cutArr line is an infinite loop?
96street
@96street
Jul 07 2016 02:32
but how does that relate to this block?: !arr2.indexOf(arr2[i])
yesungC
@yesungc
Jul 07 2016 02:33
@Chrono79 hey is this how you push to an array? collection[id][prop].push(value);
Stefan Bekirov
@bekir0v
Jul 07 2016 02:33
@Chrono79
how to set it
Jon
@jcmockbee
Jul 07 2016 02:34

Hi working on the record collection challenge and have got bogged down I am coding within the function but and trying to push through data. // Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

var writeFunction = collection [id].artist[value];

var complete = writeFunction.push('tracks', '');

return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");


Am I even close?

Diego Mayer
@Chrono79
Jul 07 2016 02:34
@96street indexOf returns the array indice of the element you're searching if it find it or -1 if it doesn't find it
@bekir0v with =
@yesungc yes
Shailesh Kumar
@sksundram
Jul 07 2016 02:34
What's the difference between /n (newline) and /r (carriage return)? When to use which one as both, according to me, do somewhat the same thing.
Diego Mayer
@Chrono79
Jul 07 2016 02:34
@jcmockbee far from it :( try reading this: :point_up: 6 de julio de 2016 22:59
Kyle King
@Kyle-King
Jul 07 2016 02:35

I don't understand why I keep getting "TypeError: collection[id].push is not a function"

if (prop !== "tracks" && value !== "") {
if (collection[id].hasOwnProperty("tracks") === true) {
collection[id].tracks.push(value);
} else {
collection[id].push("tracks");
collection[id].tracks.push(value);}
}

Diego Mayer
@Chrono79
Jul 07 2016 02:36
@Kyle-King collection[id] is an object, not an array, so it hasn't a push method

@DuXingXia233
Jul 07 2016 02:36
@Kyle-King it means collection[id] is not Array
Stefan Bekirov
@bekir0v
Jul 07 2016 02:36
@Chrono79
Thank you
CamperBot
@camperbot
Jul 07 2016 02:36
bekir0v sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
96street
@96street
Jul 07 2016 02:36
but I havent written '> -1' or '> 0' in my if statment so struggling to see why it matters here? @Chrono79
CamperBot
@camperbot
Jul 07 2016 02:37
api offline
Kyle King
@Kyle-King
Jul 07 2016 02:37
@Chrono79 && @DuXingXia233 is push not a valid function for objects?

@DuXingXia233
Jul 07 2016 02:38
@Kyle-King only Array's prototype has this method
Diego Mayer
@Chrono79
Jul 07 2016 02:38
@96street when you negate like this !arr2.indexOf(arr2[i]) it's the same as this arr2.indexOf(arr2[i]) === 0 note that this is only true for i === 0
one of those 2 should be arr1
Josh
@joshweaver23
Jul 07 2016 02:40
@Chrono79
Alex N.
@N0bl3
Jul 07 2016 02:40
Hi guys! Is it possible to get html from an ajax call and then click on it without the user noticing?
Michael R
@Myst3420
Jul 07 2016 02:40
    for (var i = size; i <= arr.length; i + size) {
var cutArr = arr.slice(x, y);
finalArr.push(cutArr);
x += 2;
y += 2;
}
CamperBot
@camperbot
Jul 07 2016 02:40
:bulb: to format code use backticks!  more info
Alex N.
@N0bl3
Jul 07 2016 02:41
I need to make it in order to target an element for which i don't have the ID
96street
@96street
Jul 07 2016 02:42
@Chrono79 ok that makes sense. but going by what you said how i've written it should still work? I just needa add arr1 in there
Michael R
@Myst3420
Jul 07 2016 02:42
Can someone tell me why line 2 is an infinite loop?
yesungC
@yesungc
Jul 07 2016 02:42
@veronicarbulu are you still online? I solved it
Diego Mayer
@Chrono79
Jul 07 2016 02:42
@96street no, you should test for -1 or !== -1 depending on what you do next
First I would concat the 2 arrays, and then I would filter against arr1 and arr2 using indexOf

@DuXingXia233
Jul 07 2016 02:43
@Myst3420 Full code, pls. we cannot help with part of ur code
Josh
@joshweaver23
Jul 07 2016 02:44
@Chrono79 thanks for the help, got it figured out from the challenge you linked
CamperBot
@camperbot
Jul 07 2016 02:44
joshweaver23 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1439 | @chrono79 |http://www.freecodecamp.com/chrono79
eliza khachatryan
@Elijbet
Jul 07 2016 02:45
Hi guys, is anyone available to help me with javascript Profile lookup assignement?
Diego Mayer
@Chrono79
Jul 07 2016 02:45
@joshweaver23 :+1: it wasn't that hard after refreshing that wasn't it ;)
96street
@96street
Jul 07 2016 02:45
function diffArray(arr1, arr2) {
var newArr = [];

for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(arr2.indexOf(arr1[i]) === -1) {
newArr.push(arr2[j]);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
@Chrono79 is that getting there
(if an object in the first arr is equal to an object in the second arr == false)
Michael R
@Myst3420
Jul 07 2016 02:46
function chunkArrayInGroups(arr, size) {
// Break it up.
var x = 0;
var y = size - 1;
var finalArr = [];

for (var i = size; i <= arr.length; i + size) {
var cutArr = arr.slice(x, y);
finalArr.push(cutArr);
x += 2;
y += 2;
}

return finalArr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Diego Mayer
@Chrono79
Jul 07 2016 02:47
@96street closer, but I don't see how j and i relate themselves

@DuXingXia233
Jul 07 2016 02:48
@Myst3420 ,ur code i+size does not change i's value;
so the condtion i<= arr.length never happen
CruftMaster
@CruftMaster
Jul 07 2016 02:48
i need help with Arguments optional.


var args = Array.from(arguments);

for(i=0;i<args.length;i++){

if(isNaN(args[i])){
return ;
}
}

var singleVal = args.reduce(function(previousVal, singleVal) {
return previousVal + singleVal;
},0);

return singleVal;
}

addTogether(2,"f");
96street
@96street
Jul 07 2016 02:48
function diffArray(arr1, arr2) {
var newArr = [];

for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(arr2.indexOf(arr1[i]) === -1) {
newArr.push(arr1[i]);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
That worked for a few tests so i think i just needa to the other half of the code
Samuel Fitzsimmons
@samfitz1
Jul 07 2016 02:49
@yesungc what did you end up doing?
CruftMaster
@CruftMaster
Jul 07 2016 02:49
clintonjohn
@clintonjohn
Jul 07 2016 02:49
I'm on beginning algorithms. Will FCC go over functional programming techniques in the intermediate and advanced algorithms?
Diego Mayer
@Chrono79
Jul 07 2016 02:50
@96street think what happens with this test: diffArray([1, 2, 3, 5, 6], [1, 2, 3, 4, 5]);
6 doesn't exist in the second array, so you'll push 6 arr2.length times in newArr
clintonjohn
@clintonjohn
Jul 07 2016 02:50
If so, I may just do the beginning ones the easy way

@DuXingXia233
Jul 07 2016 02:51
@Myst3420 got it ?
clintonjohn
@clintonjohn
Jul 07 2016 02:51
Even if they are longer than necessary
96street
@96street
Jul 07 2016 02:51
@Chrono79 4 you mean?
Diego Mayer
@Chrono79
Jul 07 2016 02:51
no, 6. I provided a new test where 6 is in arr1 and not in arr2
Michael R
@Myst3420
Jul 07 2016 02:51
@DuXingXia233 The argument coming in for size is 2. So it wouldn't be 2 + 2 to move the loop along?
96street
@96street
Jul 07 2016 02:52
there is no 6 in either arr?
oh your referring to a test
gotcha
Mike Haslam
@Ongomobile
Jul 07 2016 02:55
Hello Campers! I am having a hard time writing a calculate function. What my app does is calculate a price from quantity selected from input-setpper (imported library)then multiply by a value and display in textfield. I got it to calculate for 1 stepper and display in textfield but can't figure out how to add the subtotals of other steppers to TotalField. Also need to figure out how to subtract all dynamicly. here is link to input-stepper,js libarary https://github.com/AanZee/input-stepper and here is my codepen Thanks for helping! http://codepen.io/Ongomobile/pen/kXogvZ
96street
@96street
Jul 07 2016 02:55
this satisifes 6/8 tests @Chrono79
function diffArray(arr1, arr2) {
var newArr = [];

for(var i=0;i<arr1.length;i++) {
for(var j=0;j<arr2.length;j++) {
if(arr2.indexOf(arr1[i]) === -1) {
newArr.push(arr1[i]);
}
else if(arr1.indexOf(arr2[j]) === -1) {
newArr.push(arr2[j]);
}
}
}
return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
but like you said it pushes it arr.length times: it's returning [4,4,4,4]

@DuXingXia233
Jul 07 2016 02:56
@Myst3420 at the end of loop, u just ask computer to calculate i +2 and do nothing to i, so only 2+2 every loop, the loop cannot meet the condition and cannot stop.
Jack
@jh0l
Jul 07 2016 02:57
help lookup
CamperBot
@camperbot
Jul 07 2016 02:57

# Challenge Profile Lookup

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

### :checkered_flag: Problem Explanation:

We have an array of objects representing different people in our contacts lists.

A lookUpProfile() function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the value of that property.

If firstName does not correspond to any contacts then return No such contact.

If prop does not correspond to any valid properties then return No such property.

• Change the code below // Only change code below this line and up to // Only change code above this line.
• Ensure that you are editing the inside of the lookUpProfile() function.
Diego Mayer
@Chrono79
Jul 07 2016 02:57
@96street better concat both arrays and either use filter or 2 separated loops (not nested) to remove repeated elements or build a new array with not repeated
Michael R
@Myst3420
Jul 07 2016 02:59
@DuXingXia233 I understand now. Thank you
CamperBot
@camperbot
Jul 07 2016 02:59
myst3420 sends brownie points to @duxingxia233 :sparkles: :thumbsup: :sparkles:

@DuXingXia233
Jul 07 2016 03:00
@Myst3420 yep, have good coding and watch ur code.
Ian Robbins
@ierobbins
Jul 07 2016 03:00
This message was deleted
Jack
@jh0l
Jul 07 2016 03:02
can I use && in the condition of a for loop?
Diego Mayer
@Chrono79
Jul 07 2016 03:04
@Jhollond yes
var stop = false;
for (var i=0; i<10 && stop===false; i++) { //this loop prints from 0 to 5
console.log(i);
if (i==5) stop = true;
}
Wali Gauvin
@Docwali777
Jul 07 2016 03:05

Help with using Objects fopr Lookups ----------------------------------function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {

  "bravo":"Boston",

"charlie": "Chicago",
"delta": "Denver",

"echo": "Easy",

"foxtrot": "Frank",

};

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

// Change this value to test
phoneticLookup("charlie");

CamperBot
@camperbot
Jul 07 2016 03:05
no wiki entry for: with using objects fopr lookups ----------------------------------function phoneticlookupval var result only change code below this line var lookup alphaadams bravoboston charlie chicago delta denver echo easy foxtrot frank only change code above this line return result change this value to testphoneticlookupcharlie
Wali Gauvin
@Docwali777
Jul 07 2016 03:06
help with. ----------
CamperBot
@camperbot
Jul 07 2016 03:06
no wiki entry for: with ----------
Wali Gauvin
@Docwali777
Jul 07 2016 03:06

function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {

  "bravo":"Boston",

"charlie": "Chicago",
"delta": "Denver",

"echo": "Easy",

"foxtrot": "Frank",

};

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

// Change this value to test
phoneticLookup("charlie");

Diego Mayer
@Chrono79
Jul 07 2016 03:06
@Docwali777 you need to change result value before returning it
Jack
@jh0l
Jul 07 2016 03:06
how do I iterate through an object in Profile Lookup?
it's not numbered so
what do I do
Daiane Piva
@daianepiva
Jul 07 2016 03:07
@bekir0v Hi Stefan, did you manage to pass the challenge "Accessing Nested Objects" by setting it to gloveBoxContents as suggested by @Chrono79 ? Im still stuck on this challenge
Diego Mayer
@Chrono79
Jul 07 2016 03:07
@Jhollond contacts is an array of objects, you can use a for loop
Stefan Bekirov
@bekir0v
Jul 07 2016 03:08
@daianepiva
yes I did
Wali Gauvin
@Docwali777
Jul 07 2016 03:08
@Chrono79 - am I correct to set -- var lookup = {
Jack
@jh0l
Jul 07 2016 03:08
so how do I go to the next id in the array?
it never told me
Diego Mayer
@Chrono79
Jul 07 2016 03:09
@Docwali777 you have to change result value using lookup and val, review this challenge: https://www.freecodecamp.com/challenges/accessing-objects-properties-with-variables
Jack
@jh0l
Jul 07 2016 03:09
are the objects numbered?
Daiane Piva
@daianepiva
Jul 07 2016 03:09
@bekir0v Did you have something like this
myStorage.car.inside["glove box"] = gloveBoxContents ;
? I keep getting an error
Stefan Bekirov
@bekir0v
Jul 07 2016 03:10
@daianepiva you should make gloveBoxContents = "maps"
just change the sides
Diego Mayer
@Chrono79
Jul 07 2016 03:10
@Jhollond the first one is your array[0], and so on
@daianepiva assignation goes from right to left
Stefan Bekirov
@bekir0v
Jul 07 2016 03:11
@daianepiva gloveBoxContents should be on front
Daiane Piva
@daianepiva
Jul 07 2016 03:11
@bekir0v Thanks, it worked. Do you know why the order matters?
CamperBot
@camperbot
Jul 07 2016 03:11
daianepiva sends brownie points to @bekir0v :sparkles: :thumbsup: :sparkles:
Kyle King
@Kyle-King
Jul 07 2016 03:12
omg that record challenge was a nightmare
Stefan Bekirov
@bekir0v
Jul 07 2016 03:12
because it's a vra
Jack
@jh0l
Jul 07 2016 03:12
@Kyle-King wait until you get to Profile Lookup lol
Stefan Bekirov
@bekir0v
Jul 07 2016 03:12
@daianepiva it's var
Daiane Piva
@daianepiva
Jul 07 2016 03:12
@bekir0v sure! Makes sense, thanks a bunch
CamperBot
@camperbot
Jul 07 2016 03:12
daianepiva sends brownie points to @bekir0v :sparkles: :thumbsup: :sparkles:
:warning: daianepiva already gave bekir0v points
Kyle King
@Kyle-King
Jul 07 2016 03:12
looking forward to it!
Stefan Bekirov
@bekir0v
Jul 07 2016 03:13
@daianepiva anytime
Jack
@jh0l
Jul 07 2016 03:13
is this really hard or am I retarded
Kyle King
@Kyle-King
Jul 07 2016 03:14
What lesson number is it?
Need to prepare.
Diego Mayer
@Chrono79
Jul 07 2016 03:15
challenges haven't numbers, they have names
those numbers are this
help brownie points
CamperBot
@camperbot
Jul 07 2016 03:15

# Brownie Points

The number beside your picture on Free Code Camp tells you how many Brownie Points you have.

There are two ways you can get Brownie Points:

1. Complete challenges - you get one point per challenge you complete
2. Help other campers in chat - each time you help another camper and they thank you (by typing "thanks @yourname"), you will get a point

Brownie Points help you look like the kind of person who codes a lot, shares relevant links, and helps people.

Jack
@jh0l
Jul 07 2016 03:16
thanks @Chrono79
CamperBot
@camperbot
Jul 07 2016 03:16
jhollond sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1440 | @chrono79 |http://www.freecodecamp.com/chrono79
Jack
@jh0l
Jul 07 2016 03:17
I still don't understand how to iterate through each of the firstName things
I am lost
bitgrower
@bitgrower
Jul 07 2016 03:17
which challenge is that, @Jhollond -- is that Profile Lookup ?
Diego Mayer
@Chrono79
Jul 07 2016 03:17
You have to iterate over contacts array and access each contact property
Jack
@jh0l
Jul 07 2016 03:17
yep profile lookup
do I use hasOwnProperty?
bitgrower
@bitgrower
Jul 07 2016 03:18
yes, .hasOwnProperty is very useful in at least one line of code in the challenge !
and I'm not saying it that way to imply that it's more ... just that I don't remember, but I think it's only one line ...
Jack
@jh0l
Jul 07 2016 03:19
: D
Diego Mayer
@Chrono79
Jul 07 2016 03:20
@bitgrower @Jhollond somewhere you had to return no such property, so I'd say it is ;)
Jack
@jh0l
Jul 07 2016 03:20
DAMNNNNN THIS IS HURTING MY HEAD
natural data corruption
@primaveraentalca
Jul 07 2016 03:21
hi guys, i need some help with the Profile Lookup exercise
Om Carrasquillo
@oc2215
Jul 07 2016 03:21
Does anyone know if "console.log() is an appropriate output when using switch statements? Nothing is happening when I run the code:
case 1:
console.log("alpha");
break;
  case 2:
console.log("beta");
break;

case 3:
console.log("gamma");
break;

case 4:
console.log("delta");
break;
}
Jack
@jh0l
Jul 07 2016 03:21
var contactsCopy = JSON.parse(JSON.stringify(contacts));
is this important
bitgrower
@bitgrower
Jul 07 2016 03:21
@Jhollond - take it step by step -- don't try to code everything all at once ...
look at the instructions and take each of them one by one ... and ask yourself ... how would I do that ?
Rose
@AIAGAX1
Jul 07 2016 03:22
Hello, I need some help- I'm stuck on Escaping Literal Quotes in Strings.
Kyle King
@Kyle-King
Jul 07 2016 03:22
@oc2215 try 'return "string"'
lettda
@lettda
Jul 07 2016 03:22
ok what am I missing here it just returns null instead of the repeated string
function repeatStringNumTimes(str, num) {
var newString = str;
if (num > 0) {
return newString * num;
} else
return "";
}

repeatStringNumTimes("abc", 3);
bitgrower
@bitgrower
Jul 07 2016 03:22
@Chrono79 I think I've seen some solutions where it wasn't used ... but they weren't the most elegant soluions ... :)
Wali Gauvin
@Docwali777
Jul 07 2016 03:22
Anybody with a useful hint - for using OBJECTS for LOOKUP -

var lookup = {

  "bravo":"Boston",

"charlie": "Chicago",
"delta": "Denver",

"echo": "Easy",

"foxtrot": "Frank",

};

Jack
@jh0l
Jul 07 2016 03:22
okay so the thing that's confusing me is
in record collection challenge
Diego Mayer
@Chrono79
Jul 07 2016 03:23
@bitgrower yes, maybe they tested using !contacts[i][prop] or something like that
Jack
@jh0l
Jul 07 2016 03:23
there was 1 id for each object property
but now there's 4
I don't
i just
Diego Mayer
@Chrono79
Jul 07 2016 03:24
@Docwali777 yes, now change result value using lookup and val, hint: use bracket notation
Kyle King
@Kyle-King
Jul 07 2016 03:24
lol your frustration is entertaining at least @Jhollond
bitgrower
@bitgrower
Jul 07 2016 03:24
@Jhollond -- you have an array of objects .. each object has 1 or more properties ... :)
Jack
@jh0l
Jul 07 2016 03:25
where did I go wrong
bitgrower
@bitgrower
Jul 07 2016 03:25
once you get the hang of it, you'll see using properties is really sweet ... because you don't have to iterate thru them ... you just access them !
Rose
@AIAGAX1
Jul 07 2016 03:25

var myStr = "I am a 'double quoted\' string inside\ 'double quotes\"."; // Change this line

How do I use two double quotes (") and four esccaped double quotes (\"). ??

bitgrower
@bitgrower
Jul 07 2016 03:25
I dunno @Jhollond -- describe the data structure for me !
clintonjohn
@clintonjohn
Jul 07 2016 03:26
@cllintonjohn thanks!
CamperBot
@camperbot
Jul 07 2016 03:26
clintonjohn sends brownie points to @cllintonjohn :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for cllintonjohn
Diego Mayer
@Chrono79
Jul 07 2016 03:26
@AIAGAX1 you got the instructions wrong, you need 2 single quotes (') and four double quotes (")
clintonjohn
@clintonjohn
Jul 07 2016 03:26
Kyle King
@Kyle-King
Jul 07 2016 03:26
@AIAGAX1 instead of focusing on the quotes inside the string, focus on the encapsulating quotes
Rose
@AIAGAX1
Jul 07 2016 03:26
I don't know how that happened?
Diego Mayer
@Chrono79
Jul 07 2016 03:27
reset and start again @AIAGAX1
Kyle King
@Kyle-King
Jul 07 2016 03:27
that ---^
Jack
@jh0l
Jul 07 2016 03:27
@clintonjohn no u
Rose
@AIAGAX1
Jul 07 2016 03:27
Thank you, @Chrono79
CamperBot
@camperbot
Jul 07 2016 03:27
aiagax1 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1441 | @chrono79 |http://www.freecodecamp.com/chrono79
Om Carrasquillo
@oc2215
Jul 07 2016 03:27
return "string" just returns "string" when I run the test. It doesn't return the statements on console.log for each case.
Kyle King
@Kyle-King
Jul 07 2016 03:28
@oc2215 replace "string" with what every you want. return var return "pizza"
Diego Mayer
@Chrono79
Jul 07 2016 03:28
@oc2215 I think he meant use return instead of console.log, but I could be wrong too
Rose
@AIAGAX1
Jul 07 2016 03:28
Thank you for the insight @Kyle-King
CamperBot
@camperbot
Jul 07 2016 03:28
aiagax1 sends brownie points to @kyle-king :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for kyle-king
Wali Gauvin
@Docwali777
Jul 07 2016 03:29
@Chrono79 ???val = result[lookup];
natural data corruption
@primaveraentalca
Jul 07 2016 03:29
I'm stucked in the Profile Lookup excercise, it works ok just for the first object and I dont know why. This is my function:
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i=0; i<contacts.length; i++) {
if (firstName==contacts[i].firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
} else {
return "No such contact";
}
}
// Only change code above this line
}
Diego Mayer
@Chrono79
Jul 07 2016 03:29
@Docwali777 well, you used all 3, but in the wrong places
and you want to set the value of result, so it should be at the left of the = sign
bitgrower
@bitgrower
Jul 07 2016 03:30
@primaveraentalca well ... for no such contact consider this ... if I have a bag of 12 marbles, how many do I have to look at to know that there are no black marbles in my bag ?
Jack
@jh0l
Jul 07 2016 03:30
how can marbles be real if our eyes aren't?
Om Carrasquillo
@oc2215
Jul 07 2016 03:31
@lettda missing '{' after else
Jack
@jh0l
Jul 07 2016 03:31
black's not a color by the way
Diego Mayer
@Chrono79
Jul 07 2016 03:32
@primaveraentalca think of this too, you return in every possible option, so your loop will run only once that way (return exits your function)
bitgrower
@bitgrower
Jul 07 2016 03:32
@Jhollond nothing is real, it's all an illusion -- so, just play along with the game anyway ...
bitgrower @bitgrower thinks @Jhollond has gone into that frustrated programmer stage which makes him ornery
Wali Gauvin
@Docwali777
Jul 07 2016 03:33
@Chrono79 you are the man...... Brownie points for you...
Diego Mayer
@Chrono79
Jul 07 2016 03:33
:+1:
Wali Gauvin
@Docwali777
Jul 07 2016 03:33
result = lookup[val];
bitgrower
@bitgrower
Jul 07 2016 03:33
you have to thank him to give him some ...
like this ... thanks, @Chrono79
CamperBot
@camperbot
Jul 07 2016 03:33
bitgrower sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1442 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 07 2016 03:33
wiiii, free brownies ;) thanks @bitgrower
CamperBot
@camperbot
Jul 07 2016 03:33
chrono79 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1131 | @bitgrower |http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Jul 07 2016 03:34
@chrono gets lots of my demo brownie points ... :)
and besides he works hard and doesn't get nearly enough ... :)
I don't understand what they're asking.
Jack
@jh0l
Jul 07 2016 03:37
how do I tell the LookupProfile cunction which likes array I am referring to
Diego Mayer
@Chrono79
Jul 07 2016 03:38
Jack
@jh0l
Jul 07 2016 03:38
THEY ONLY DID NUMBERED SINGLE DIMENSION ARRAYS
WHY
like
GideonCahill
@GideonCahill
Jul 07 2016 03:38
@Chrono79 Ok let me try that
Jack
@jh0l
Jul 07 2016 03:39
the examples they showed me with for loops were all just numbers in single dimensions
okay 1 was 2 dimensions
Kyle King
@Kyle-King
Jul 07 2016 03:40
2 dimensions is just two 1 dimensions man
divide and conquer
Jack
@jh0l
Jul 07 2016 03:41
but they're were all numbers
now I have to suddenly know how to iterate names
Kyle King
@Kyle-King
Jul 07 2016 03:41
strings are just numbers in an array based on position
Jack
@jh0l
Jul 07 2016 03:41
do I make an array of names
is that what i do?
I make an array of names?
Kyle King
@Kyle-King
Jul 07 2016 03:42
Im not there, but sounds like it
Im just a baby
Jack
@jh0l
Jul 07 2016 03:43
u a cooty man @Kyle-King
Diego Mayer
@Chrono79
Jul 07 2016 03:43
@Jhollond contacts is as its name suggests a contacts list
each contact is an element of contacts array
So use a for loop and contacts[i] is the ith contact, as simple as that
Then test for firstName, and whatever property thay ask you to
GideonCahill
@GideonCahill
Jul 07 2016 03:43
This message was deleted
Kyle King
@Kyle-King
Jul 07 2016 03:44
a/s/l? Maybe I'll call in 18 years.
GideonCahill
@GideonCahill
Jul 07 2016 03:45
@Chrono79
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
myNoun + "is" + myAdjective + "and they do" + myVerb "very" + myAdverb;

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
Maria Trujillo
@mtruj013
Jul 07 2016 03:45
@pk422 Apparently my formula was right, just had a really silly typo lol. Thanks for responding.
CamperBot
@camperbot
Jul 07 2016 03:45
mtruj013 sends brownie points to @pk422 :sparkles: :thumbsup: :sparkles:
Jack
@jh0l
Jul 07 2016 03:45
@Chrono79 i as in the number or the firstName
CamperBot
@camperbot
Jul 07 2016 03:45
Jack
@jh0l
Jul 07 2016 03:45
i as in from 0 to 3 or from Akira to Kristian
Kyle King
@Kyle-King
Jul 07 2016 03:46
you need spaces in your strings @GideonCahill and your didn't set the variable to = the string you made.
Diego Mayer
@Chrono79
Jul 07 2016 03:46
@GideonCahill see again the challenge I told you, so you see where you have to put the + and the spaces between words
@Jhollond yes, i will go between 0 and 3
Travis Arbon
@travisarbon
Jul 07 2016 03:47
Hey guys, I'm doing the Mutations basic algorithm challenge, and I ended up writing a chunk of code that passes the test but isn't actually functional. I know that the problem is that I'm checking the total number of matches against the length of the string, but I'm not sure how else to do it, and I don't want to move on without getting it right.
function mutation(arr) {
var total = 0;
var first = arr.shift().toString().toLowerCase();
var second = arr.pop().toString().toLowerCase().split("");
for(var i = 0; i < second.length; i++){
total += first.indexOf(second[i]);
}

mutation(["Mary", "A"]);
MeonAigeanta
@MeonAigeanta
Jul 07 2016 03:48

Arguments Optional Challenge
My code passes all of the tests except addTogether(2)([3]). It should return undefined.

How can I access the 2nd value ([3])?

var code = "formatted"
var sum = 0;
var args = Array.from(arguments);
if(typeof args[0] !== 'number')
return undefined;
if(args.length <2){
return function(y) {
return x + y;
};
}else{
if(typeof args[1] !== 'number')
return undefined
//
//    How to test for 2nd function value?
//
for(var i = 0; i< args.length; i++){
sum += args[i];
}
return sum;
}
}

addTogether(2)([3]);
Jack
@jh0l
Jul 07 2016 03:48
but isn't firstName a prop? @Chrono79
Diego Mayer
@Chrono79
Jul 07 2016 03:48
@travisarbon why shift and pop when you could use 0 and 1 as indexes?
Remember returning early challenge, with only one mismatch you could say false
@Jhollond yes, one of many
Travis Arbon
@travisarbon
Jul 07 2016 03:49
@Chrono79 you're right. that would be simpler and more functional
Mustafijur rahman
@Dinar717
Jul 07 2016 03:50
@MeonAigeanta y is your 2nd argument
Greg Munker
@Gmunker
Jul 07 2016 03:50
hello everyone, I'm looking for some help with "Binary Agents" (i am not looking for the answer that is a quick google search away), i'm looking for some guidance on where to start. I know the absolute basics of binary and even that is foggy, so looking at charCodeAt, and fromCharCode is not helping me at all. Can someone please help point me in the general direction i need to look at.
Jack
@jh0l
Jul 07 2016 03:50
then how to a access a prop if I can't go contacts.firstName.prop
doesn'
natural data corruption
@primaveraentalca
Jul 07 2016 03:50
@Chrono79 I finally made it, thanks man.
CamperBot
@camperbot
Jul 07 2016 03:50
primaveraentalca sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1443 | @chrono79 |http://www.freecodecamp.com/chrono79
Jack
@jh0l
Jul 07 2016 03:50
t make any sense
Mustafijur rahman
@Dinar717
Jul 07 2016 03:50
@MeonAigeanta you can check if its a number or not.
Kyle King
@Kyle-King
Jul 07 2016 03:51
shouldn't it be contacts[firstName]prop @Jhollond
wouldn't FN be a variable?
Jack
@jh0l
Jul 07 2016 03:52
@Kyle-King it woudn't work any way because firstname isn't the parent of other props
or like
MeonAigeanta
@MeonAigeanta
Jul 07 2016 03:52
@Dinar717 How do I access the value? I tried args[1] and that doesn't work.
Diego Mayer
@Chrono79
Jul 07 2016 03:52
@Jhollond contacts is as its name suggests a contacts list
each contact is an element of contacts array
So use a for loop and contacts[i] is the ith contact, as simple as that
Then test for firstName, and whatever property thay ask you to
Mustafijur rahman
@Dinar717
Jul 07 2016 03:53
@MeonAigeanta you can access the 2nd value inside the return function.
Diego Mayer
@Chrono79
Jul 07 2016 03:53
So, contacts[i].firstName is one of the things you want to test, use bracket notation when needed
Mustafijur rahman
@Dinar717
Jul 07 2016 03:53
@MeonAigeanta where you are adding the x+y.
its y
Diego Mayer
@Chrono79
Jul 07 2016 03:53
@Kyle-King firstName in this particular case is a property too, so no need for bracket notation here
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
...
MeonAigeanta
@MeonAigeanta
Jul 07 2016 03:55
@Dinar717 Thanks. I haven't really grasped what is going on with closures.
CamperBot
@camperbot
Jul 07 2016 03:55
meonaigeanta sends brownie points to @dinar717 :sparkles: :thumbsup: :sparkles:
Om Carrasquillo
@oc2215
Jul 07 2016 03:55
@Kyle-King oh man I feel silly. Thanks for clearing that up for me. Thanks @lettda
CamperBot
@camperbot
Jul 07 2016 03:55
oc2215 sends brownie points to @kyle-king and @lettda :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for kyle-king
I've solved the problem but not in the intended way....
Diego Mayer
@Chrono79
Jul 07 2016 04:03
@GideonCahill // Your code below this line
leave var result = ""; up there and below the comment write result = what you have
GideonCahill
@GideonCahill
Jul 07 2016 04:03
@Chrono79 Thanks!
CamperBot
@camperbot
Jul 07 2016 04:03
gideoncahill sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1444 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 07 2016 04:04
nite to all (at least it'a 1AM here)
Rose
@AIAGAX1
Jul 07 2016 04:07
Good night Chrono79 thanks for all your help :)
Travis Arbon
@travisarbon
Jul 07 2016 04:07
Fixed my problem. Just had to change what I was testing for. Instead of matches, I tested for mismatches, and then counted if there were any. Works great now.
function mutation(arr) {
var mismatch = 0;
var first = arr[0].toString().toLowerCase();
var second = arr[1].toString().toLowerCase().split("");
for(var i = 0; i < second.length; i++){
if (first.indexOf(second[i]) < 0){
mismatch += first.indexOf(second[i]);
}
} return mismatch === 0;
}

mutation(["Mary", "A"]);
Darryn Bourgeois
Jul 07 2016 04:09
help steamroller
CamperBot
@camperbot
Jul 07 2016 04:09

# Algorithm Steamroller

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

### :checkered_flag: Problem Explanation:

This problem seems simple but you need to make sure to flatten any array, regardless of the level which is what adds a bit of difficulty to the problem.

Diego
@disofu234
Jul 07 2016 04:29
anyone here finish the phone number algorithm?

function telephoneCheck(str) {
var regex = /^1?\s?$$?(?=\d\d\d$$)?\d\d\d\)?\s?-?\d\d\d-?\s?\d\d\d\d$/; return regex.test(str); } telephoneCheck("1 555)555-5555"); NixonRichard @NixonRichard Jul 07 2016 04:30 Does anyone have question about basic algos ? Diego @disofu234 Jul 07 2016 04:31 how can i make that return false? NixonRichard @NixonRichard Jul 07 2016 04:31 i have no idea is that intermidate challegne ? Diego @disofu234 Jul 07 2016 04:32 advanced NixonRichard @NixonRichard Jul 07 2016 04:32 nevermine lol Diego @disofu234 Jul 07 2016 04:32 you're good lol NixonRichard @NixonRichard Jul 07 2016 04:32 Thx lol dscandalios @dscandalios Jul 07 2016 04:33 n00b here...what's wrong with this assignment? var fahrenheit = ((celsius *= 9/5) += 32); John Cardenas @jpcode Jul 07 2016 04:33 instead of \d, you can use: [0-9]{3} @dscandalios is instead of =, because first is operation, second is assign. var fahrenheit = ((celsius * 9/5) + 32); dscandalios @dscandalios Jul 07 2016 04:34 :thumbsup: Abhishek Baliyan @abhishekdevinfo Jul 07 2016 04:34 need help John Cardenas @jpcode Jul 07 2016 04:35 sure dscandalios @dscandalios Jul 07 2016 04:35 thank you @jpcode CamperBot @camperbot Jul 07 2016 04:35 dscandalios sends brownie points to @jpcode :sparkles: :thumbsup: :sparkles: :cookie: 309 | @jpcode |http://www.freecodecamp.com/jpcode NixonRichard @NixonRichard Jul 07 2016 04:35 what s ur problem my friend @abhishekdevinfo Abhishek Baliyan @abhishekdevinfo Jul 07 2016 04:35 how to delete specific element of array NixonRichard @NixonRichard Jul 07 2016 04:35 use array slice array slice ( ur fist element , end elemetn) John Cardenas @jpcode Jul 07 2016 04:35 @Diego you can use this regex by try to understand how it works -> var telregx = /^(1\s?)?(([0-9]{3})|[0-9]{3})[\s-]?[0-9]{3}[\s-]?[0-9]{4}$/;
Abhishek Baliyan
@abhishekdevinfo
Jul 07 2016 04:35
a = [1,2,5];
i want to delete a[1]
NixonRichard
@NixonRichard
Jul 07 2016 04:36
arr.slice(begin,end);
quekzhongrui
@quekzhongrui
Jul 07 2016 04:36
need help
Abhishek Baliyan
@abhishekdevinfo
Jul 07 2016 04:36
@NixonRichard thanks
CamperBot
@camperbot
Jul 07 2016 04:36
abhishekdevinfo sends brownie points to @nixonrichard :sparkles: :thumbsup: :sparkles:
NixonRichard
@NixonRichard
Jul 07 2016 04:36
My pleasure ( =
John Cardenas
@jpcode
Jul 07 2016 04:38
@abhishekdevinfo i think you are looking for "splice" instead [1,2,3].splice(1, 1) => [1,3]
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 04:40
Can someone explain this better? I've completed the exercise, but I don't understand this very well.
"sort can be passed a compare function as a callback. The compare function should return a negative number if a should be before b, a positive number if a should be after b, or 0 if they are equal.
If no compare (callback) function is passed in, it will convert the values to strings and sort alphabetically."

var array = [1, 12, 21, 2];

// Only change code below this line.

array.sort(function(a,b) {
return b - a;
});
Abhishek Baliyan
@abhishekdevinfo
Jul 07 2016 04:40
@jpcode thank u soo much
CamperBot
@camperbot
Jul 07 2016 04:40
abhishekdevinfo sends brownie points to @jpcode :sparkles: :thumbsup: :sparkles:
Diego
@disofu234
Jul 07 2016 04:43
@jpcode thank you dude! i figured it out
CamperBot
@camperbot
Jul 07 2016 04:43
disofu234 sends brownie points to @jpcode :sparkles: :thumbsup: :sparkles:
John Cardenas
@jpcode
Jul 07 2016 04:45
@JonathonLLopez that is like b > a then b - a > 0
@JonathonLLopez , function( a , b ) is for the compare part, example: [ 1, 2, 3 ] in one iterarion ( a= 1, b = 2 ) b - a > 0 -> 2 - 1 > 0 then array will swap to : [ 2 , 1, 3 ] and continue :)
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Jul 07 2016 04:49
@jpcode beat me to it
to be quite honest the concept was really hard for me to understand as well in the beginning!
one thing that I would definitely recommend is trailing the code inside a debugger, it really helped me understand sorting functions
John Cardenas
@jpcode
Jul 07 2016 04:52
@AleCx4 yep thats right, you can add a console.log(a,b,b-a) to see how it works internally.
Joseph
@revisualize
Jul 07 2016 04:52
YO! How can I help?
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Jul 07 2016 04:53
@revisualize slkjdkajalksd what is the meaning of life?
ha
got u
Joseph
@revisualize
Jul 07 2016 04:54
@AleCx4 42
Caleb
@caltron3030
Jul 07 2016 04:54
Hey all! I'm having trouble making this function work. It's supposed to return the shifted element.
oh whoops!
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Jul 07 2016 04:54
@revisualize you da bomb!
@caltron3030 show it Caleb
Caleb
@caltron3030
Jul 07 2016 04:55
how do I do that?
John Cardenas
@jpcode
Jul 07 2016 04:55
@caltron3030 show the code :)
Caleb
@caltron3030
Jul 07 2016 04:56

function nextInLine(arr, item) {

arr.push(item);
arr.shift(arr[0]);

return arr.push(arr[0]); // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

how do i make it show in the black box? lol
Abhishek Baliyan
@abhishekdevinfo
Jul 07 2016 04:56
hi everyone
Caleb
@caltron3030
Jul 07 2016 04:56
I'm such a n00b
Stefan Bekirov
@bekir0v
Jul 07 2016 04:57
hi
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++)

product *= multiplyAll;
}

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Mustafijur rahman
@Dinar717
Jul 07 2016 04:57
@caltron3030 return it;
Caleb
@caltron3030
Jul 07 2016 04:57
how did you do that @bekir0v
Abhishek Baliyan
@abhishekdevinfo
Jul 07 2016 04:58
@bekir0v arr[i][j]
Caleb
@caltron3030
Jul 07 2016 04:58
it doesn't return the first element though
Stefan Bekirov
@bekir0v
Jul 07 2016 04:59
what I miss
Caleb
@caltron3030
Jul 07 2016 04:59
it has an X by "nextInLine([5,6,7,8,9], 1) should return 5"
Abhishek Baliyan
@abhishekdevinfo
Jul 07 2016 04:59
@bekir0v product *= arr[i][j]
John Cardenas
@jpcode
Jul 07 2016 05:00
@caltron3030 just return arr.shift();
Caleb
@caltron3030
Jul 07 2016 05:00
now I have all red X's
Stefan Bekirov
@bekir0v
Jul 07 2016 05:01
@abhishekdevinfo Thank you
CamperBot
@camperbot
Jul 07 2016 05:01
bekir0v sends brownie points to @abhishekdevinfo :sparkles: :thumbsup: :sparkles:
Joseph
@revisualize
Jul 07 2016 05:01
@caltron3030 You shift returns. YOu need to re-read the instructions.
John Cardenas
@jpcode
Jul 07 2016 05:01
@caltron3030 what FC problem is? title?
Joseph
@revisualize
Jul 07 2016 05:01
// Write a function nextInLine which takes
// an array (arr) and a number (item) as arguments.
function nextInLine(arr, item) {
// Add the number to the end of the array,

// then remove the first element of array.
// The nextInLine function should
// then return the element that was removed.
return item; // Change this line
}
Caleb
@caltron3030
Jul 07 2016 05:01
Stand in Line
John Cardenas
@jpcode
Jul 07 2016 05:02
@caltron3030 instruction just say: arr.push(item) and next return arr.shift();
Joseph
@revisualize
Jul 07 2016 05:02
@caltron3030 You have everything. You'....
well.. nevermind.
Caleb
@caltron3030
Jul 07 2016 05:03
then why is it not working?

function nextInLine(arr, item) {

arr.push(item);
arr.shift();

return arr.shift(); // Change this line
}

John Cardenas
@jpcode
Jul 07 2016 05:03
jusr return arr.shift(). remove the previous line.

function nextInLine(arr, item) {

arr.push(item);
return arr.shift(); // Change this line
}

Caleb
@caltron3030
Jul 07 2016 05:04
I was overthinking. Thanks guys!
Joseph
@revisualize
Jul 07 2016 05:06
@bekir0v multiplyAll is your function. You want to have product be multiplied by the array value.
96street
@96street
Jul 07 2016 05:13
can someone explain to me how this code is working?
 function diffArray(arr1, arr2) {
var newArr = arr1.concat(arr2);

function check(item) {
if (arr1.indexOf(item) === -1 || arr2.indexOf(item) === -1) {
return item;
}
}

return newArr.filter(check);
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
i don't get how the if statement is able to target arr1 when it filters newArr
because newArr is just one combined array
Damnme
@Damnme
Jul 07 2016 05:15

function largestOfFour(arr) {
return arr[3].sort();
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); returns [1, 1000, 1001, 857]

Markus Kiili
@Masd925
Jul 07 2016 05:16
@96street The code first combines the arrays, and then keeps those elements that don't exist in one of the original arrays (using filter method).
dscandalios
@dscandalios
Jul 07 2016 05:17
This message was deleted
This message was deleted
This message was deleted
96street
@96street
Jul 07 2016 05:18
but how is it able to recognize if an item came from the first or second arr when it's using the filter method on the combined array? @Masd925
Markus Kiili
@Masd925
Jul 07 2016 05:20
@96street It uses arr1 and arr2 there.
newArr is the combined third array.
96street
@96street
Jul 07 2016 05:21
can you translate the if statement in plain words?
Markus Kiili
@Masd925
Jul 07 2016 05:22
It tests if item (the newArr element being iterated by filter) is not found on arr1 or is not found on arr2.
The callback should actually return true there. Returning a non-zero number does the same but is not good code.
96street
@96street
Jul 07 2016 05:23
that makes sense
so the -1 should be 'true' instead?
isn't it false
Srikar Samudrala
@srikarsams
Jul 07 2016 05:28

function nextInLine(arr, item) {
arr.push();

return arr.shift(); // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

what's wrong
John Cardenas
@jpcode
Jul 07 2016 05:29
@srikarsams , arr.push(item);
Srikar Samudrala
@srikarsams
Jul 07 2016 05:29
Got it Thanks John
John Cardenas
@jpcode
Jul 07 2016 05:32
@96street , indexOf return the position of an element in array, else returns -1, example: [1,2,3].indexOf(2) -> 1
So your if statement is looking to filter just in the case that one array contain the element it means if an "-1" is returned.
NixonRichard
@NixonRichard
Jul 07 2016 05:33
yeah thas right
yang
@mhl821611704
Jul 07 2016 05:34
NixonRichard
@NixonRichard
Jul 07 2016 05:34
lol profile pic
is he ur idol ?
96street
@96street
Jul 07 2016 05:35
@jpcode thanks
CamperBot
@camperbot
Jul 07 2016 05:35
96street sends brownie points to @jpcode :sparkles: :thumbsup: :sparkles:
NixonRichard
@NixonRichard
Jul 07 2016 05:35
runningCoder81
@runningCoder81
Jul 07 2016 05:36
could use someone to look over my code to see what I'm missing
NixonRichard
@NixonRichard
Jul 07 2016 05:36
Meeee
show me ur code
runningCoder81
@runningCoder81
Jul 07 2016 05:37

function largestOfFour(arr) {
// You can do this!
var biggest = 0;
var array = [];

for ( var i = 0; i < arr.length; i++ )
{
for ( var j = 0; j < arr[i].length; j++ )
{
var x = arr[i][j];

      if ( x > biggest )
{
biggest = x;
}

}

array.push(biggest);

}

return array;
}

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

John Cardenas
@jpcode
Jul 07 2016 05:39
@runningCoder81 return biggest; and remove the array.push(biggest)
DJ
@qualitymanifest
Jul 07 2016 05:39
@runningCoder81 i havent taken a thorough look yet but i'm guessing need to reset your biggest variable with every subarray iteration
John Cardenas
@jpcode
Jul 07 2016 05:39
if you try to restun just the biggest :)
runningCoder81
@runningCoder81
Jul 07 2016 05:40
this returns 27, 27, 39, 1001 it should return 27, 5, 39, 1001
DJ
@qualitymanifest
Jul 07 2016 05:41
@runningCoder81 yeah i just looked at it, you just need to reset biggest to 0 before each subarray
that will work
John Cardenas
@jpcode
Jul 07 2016 05:41
Ok, looks like you need to initialize biggest for each i instead.
runningCoder81
@runningCoder81
Jul 07 2016 05:42
That was it!!
dan
dang
I knew I was close
Thanks @qualitymanifest @jpcode
CamperBot
@camperbot
Jul 07 2016 05:42
runningcoder81 sends brownie points to @qualitymanifest and @jpcode :sparkles: :thumbsup: :sparkles:
:star2: 1257 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
clintonjohn
@clintonjohn
Jul 07 2016 05:45
Would this solution be described recursion? http://bit.ly/29pkyiP
Markus Kiili
@Masd925
Jul 07 2016 05:45
@clintonjohn No.
John Cardenas
@jpcode
Jul 07 2016 05:45
@clintonjohn is just FP :)
Markus Kiili
@Masd925
Jul 07 2016 05:46
@clintonjohn Recursive function contains a call to the same function.
John Cardenas
@jpcode
Jul 07 2016 05:46
Well guys! Bye Bye, 00:46 am here :)
clintonjohn
@clintonjohn
Jul 07 2016 05:47
@jpcode thx
CamperBot
@camperbot
Jul 07 2016 05:47
clintonjohn sends brownie points to @jpcode :sparkles: :thumbsup: :sparkles:
clintonjohn
@clintonjohn
Jul 07 2016 05:47
@Masd925 thx
CamperBot
@camperbot
Jul 07 2016 05:47
clintonjohn sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2065 | @masd925 |http://www.freecodecamp.com/masd925
Jack
@jh0l
Jul 07 2016 05:51
what do I put in the url to stop the page from auto running tests on load
Joseph
@revisualize
Jul 07 2016 05:55
help auto
CamperBot
@camperbot
Jul 07 2016 05:55

# Disable Code Auto Run on Free Code Camp

By default, the Free Code Camp site automatically loads and runs your last recorded solution. If you have accidentally created an infinite loop or other irrecoverable error or simply don't trust the code, you can disable code auto-run by putting the following in your URL: run=disabled

Joseph
@revisualize
Jul 07 2016 05:55
Boom!
Jack
@jh0l
Jul 07 2016 06:02
it should be #&run-disabled
thanks @revisualize tho
CamperBot
@camperbot
Jul 07 2016 06:02
jhollond sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1376 | @revisualize |http://www.freecodecamp.com/revisualize
clintonjohn
@clintonjohn
Jul 07 2016 06:08
@Masd925 where does the new array created by .map reside? Is it stored somewhere?
Jack
@jh0l
Jul 07 2016 06:09
help lookup
CamperBot
@camperbot
Jul 07 2016 06:09

# Challenge Profile Lookup

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

### :checkered_flag: Problem Explanation:

We have an array of objects representing different people in our contacts lists.

A lookUpProfile() function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the value of that property.

If firstName does not correspond to any contacts then return No such contact.

If prop does not correspond to any valid properties then return No such property.

• Change the code below // Only change code below this line and up to // Only change code above this line.
• Ensure that you are editing the inside of the lookUpProfile() function.
Magnus Holm
@mghlm
Jul 07 2016 06:10
Does anyone see what is wrong here?
function Penguin(name) {
this.name = name;
this.numLegs = 2;
}

function Emperor (name) {
this.name = name;
}

Emperor.prototype = new Penguin();

var emperor = new Emperor("BOBBY");

emperor.numLegs();
clintonjohn
@clintonjohn
Jul 07 2016 06:10
help .map
CamperBot
@camperbot
Jul 07 2016 06:10

# Algorithm Map the Debris

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

### :checkered_flag: Problem Explanation:

The first thing to do is to get familiar with what the program is for by knowing what Orbital period exactly is. You've to return a new array that transforms the element's average altitude into their orbital periods. The parts generally found hard are finding the formula, implementing it and for some people, modifying objects by the key. However, something that is not very clear is the fact that your program has to be able to check for any number of objects in the array; This is what is tested on the second part.

Markus Kiili
@Masd925
Jul 07 2016 06:11
@clintonjohn The new array is created by .map() method and it is returned as a return value from .map(). You can store it on a variable or for example return it like in your example.
NixonRichard
@NixonRichard
Jul 07 2016 06:12
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
if ( value === ' ')
{delete collection[id][prop];}
else if (prop != "tracks" && value !== ''){
return collection[id][prop].push(value);
}else if (prop == 'tracks' && collection[id][prop] === ''){
var tracks = [];tracks.push(value);
}else if (prop == 'tracks' && value !== ''){
return collection[id][prop].push(value);
}}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
problem with record collection again lol
Markus Kiili
@Masd925
Jul 07 2016 06:12
@NixonRichard Test "" not " " in if ( value === ' ')
NixonRichard
@NixonRichard
Jul 07 2016 06:13
i fixed it
cannot read property 'push' of undefined
i though i defined tracks
clintonjohn
@clintonjohn
Jul 07 2016 06:15
@Masd925 thanks!
CamperBot
@camperbot
Jul 07 2016 06:15
clintonjohn sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: clintonjohn already gave masd925 points
Physicallime570
@Physicallime570
Jul 07 2016 06:18
Im stuck on Testing Objects properties 
Markus Kiili
@Masd925
Jul 07 2016 06:18
@NixonRichard Only return should be return collection; at the end of function.
Physicallime570
@Physicallime570
Jul 07 2016 06:18
// Setup
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
myObj.hasOwnProperty("pet");
myObj.hasOwnProperty("bed");

return "checkprop";
}

// Test your code by modifying these values
checkObj("gift");
96street
@96street
Jul 07 2016 06:18
Can someone help me on 'Wherefore art thou'
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.

function whatIsInAName(collection, source) {

var arr = [];
for(var objs in collection)  {
for(var obj in objs) {
if(obj===source) {
arr.push(obj);
}
}
}

return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
}
Markus Kiili
@Masd925
Jul 07 2016 06:20
@96street The inner loop needs to be over source's property keys.
Jack
@jh0l
Jul 07 2016 06:20
is it cheating if I checked the solution on the gihub wiki for Contact Lookup challenge?
Markus Kiili
@Masd925
Jul 07 2016 06:21
@Jhollond Yes, shame on you. Now do it with .reduce() method.
Jack
@jh0l
Jul 07 2016 06:21
I don't know what .reduce() means
help reduce
CamperBot
@camperbot
Jul 07 2016 06:21

# Challenge Condense Arrays with Reduce

Reduce can be useful for condensing an array of numbers into one value.

var array = [4,5,6,7,8];
var singleVal = 0;
// Only change code below this line.

var singleVal = array.reduce(function(previousVal, currentVal){

return previousVal+currentVal;

});
96street
@96street
Jul 07 2016 06:21
yor talking about: for(var obj in objs) ? @Masd925
Markus Kiili
@Masd925
Jul 07 2016 06:21
@96street Yes.
96street
@96street
Jul 07 2016 06:22
but it's just talking about the whole obj, not parts of it
so why do i have to iterate source?
i'm treating source as one object like i should
Markus Kiili
@Masd925
Jul 07 2016 06:22
@96street You need to check whether the looped object has same property values as source for all the source keys. So there is no need to loop looped objects keys.
96street
@96street
Jul 07 2016 06:23
isn't that what this is doing?:
if(obj===source)
Markus Kiili
@Masd925
Jul 07 2016 06:24
@96street That compares one key of the looped object (a string) with source object (object). Doesn't make sense.
96street
@96street
Jul 07 2016 06:24
oh so should b: if(objs===source)
Markus Kiili
@Masd925
Jul 07 2016 06:25
@96street That is always false.
@96street You need to loop source keys and check if the property values of looped object and source match. If they match for all source keys, you keep the object.
96street
@96street
Jul 07 2016 06:25
gotcha
so a third nested for loop :/ ?
bit stuck @Masd925
for(var objs in collection)  {
for(var obj in objs) {
for(var srcObj in source) {
if(// something)
}
}
}
Markus Kiili
@Masd925
Jul 07 2016 06:29
@96street Two loops is enough. Collection indices and source keys.
@96street for...in loop is not meant for iterating array indices. Simple for loop is better. Sources keys you can loop with for...in.
96street
@96street
Jul 07 2016 06:30
 var arr = [];
for(var objs in collection)  {
for(var obj in objs) {
if(collection[objs]==source) {
// push
}
}
}
close?
Markus Kiili
@Masd925
Jul 07 2016 06:30
@96street Inner loop should loop sources keys.
96street
@96street
Jul 07 2016 06:31
var arr = [];
for(var objs in collection)  {
for(var srcKeys in source) {
if(collection[objs]==source[srcKeys]) {
// push
}
}
}
Mostafa Syam
@pro-mos
Jul 07 2016 06:32

i dont understand this challenge :S help?
Markus Kiili
@Masd925
Jul 07 2016 06:32
@96street You are not accessing looped objects property value.
And push only after checking that the values match for all the source keys, not just one key.
Mostafa Syam
@pro-mos
Jul 07 2016 06:33
nevermind it was missing a space :S
Rose
@AIAGAX1
Jul 07 2016 06:35
I could use some help... with (Escaping Literal Quotes in Strings) It says - You should use two double quotes (") and four escaped double quotes (\").
var myStr = 'I am a "double quoted" string inside "double quotes".';
Rooaw
@Rooaw
Jul 07 2016 06:37
var myStr = "I am a \"double quoted\" string inside \"double quotes\"";
Coy Sanders
@coymeetsworld
Jul 07 2016 06:37
@AIAGAX1 replace the single quotes with double quotes
clintonjohn
@clintonjohn
Jul 07 2016 06:37
=> isn't supported on FCC yet?
Coy Sanders
@coymeetsworld
Jul 07 2016 06:37
@Rooaw can you try and not just provide the answers when someone is asking for help next time?
Rooaw
@Rooaw
Jul 07 2016 06:38
sorry
Coy Sanders
@coymeetsworld
Jul 07 2016 06:38
that is the right answer though
no problem @Rooaw
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 06:40
I need help with the reverse a string exercise. I think my problem is understanding the logic of what to do:

function reverseString(str) {
var array = [];

array = str.split(" ");
array.reverse(str);
array.join();
return str;
}

reverseString("hello");
Markus Kiili
@Masd925
Jul 07 2016 06:41
@JonathonLLopez Split to characters not words.
clintonjohn
@clintonjohn
Jul 07 2016 06:41
help arrow functions
CamperBot
@camperbot
Jul 07 2016 06:41
no wiki entry for: arrow functions
Rose
@AIAGAX1
Jul 07 2016 06:41
@coymeetsworld Thank You!! :smile:
CamperBot
@camperbot
Jul 07 2016 06:41
aiagax1 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1249 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Jul 07 2016 06:42
np @AIAGAX1
@JonathonLLopez also you need to assign the result of join to something
Z.G.Hao
@akidox
Jul 07 2016 06:42

Just solved the Falsy Bouncer challenge,but still something couldn’t understand.The advanced solution the wiki page shows confuses me,it’s like

function bouncer(arr) {
return arr.filter(Boolean);
}

and then I guess that it’s kind of the abbreviation of

function bouncer(arr) {
return arr.filter(function(val){
return Boolean(val);
});
}

and it turns out right,am I right?
if so,how?

clintonjohn
@clintonjohn
Jul 07 2016 06:44
Can we run ES6 code in FCC browser
Rose
@AIAGAX1
Jul 07 2016 06:44
@Rooaw I appreciate the help. :sparkles:
clintonjohn
@clintonjohn
Jul 07 2016 06:45
Markup previewer?
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 06:48
@Masd925 what do you mean by split to characters not words?

function reverseString(str) {
var array = [];

array = str.split(str);
array.reverse();
array.join(str);

return str;
}

reverseString("hello");
Markus Kiili
@Masd925
Jul 07 2016 06:50
@JonathonLLopez str.split(" "); splits the string into words (splits on spaces). str.split("") splits to array of characters (splits between every character).
To reverse, you need an array of characters, not words.
x981
@x981
Jul 07 2016 06:51
I'm in challenge https://www.freecodecamp.com/challenges/use-the-twitchtv-json-api , But i can not load twitch page, who have same problem?
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 06:52
@Masd925 oh I see. I didn't know "" could do that
Coy Sanders
@coymeetsworld
Jul 07 2016 06:54
what browser/OS @x981 ?
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 06:54
@Masd925 so I would need to do it on .join() too?
array = str.split("");
array.reverse();
array.join("");

return str;
Coy Sanders
@coymeetsworld
Jul 07 2016 06:54
I have problems running Chrome on Ubuntu 12.04, Firefox worked for me to show the video
Markus Kiili
@Masd925
Jul 07 2016 06:55
@JonathonLLopez Yes. Also remember to store (or return) the returned string.
x981
@x981
Jul 07 2016 06:55
Coc Coc browser and windows 8.1 @@coymeetsworld
It load successul on FireFox, so let i try it. Thanks @coymeetsworld
CamperBot
@camperbot
Jul 07 2016 06:56
x981 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1250 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Jul 07 2016 06:57
np @x981
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 06:57
@Masd925 so you wouldn't be returning array then?
Keone Martin
@Athaman
Jul 07 2016 06:58
@JonathonLLopez nope you need to turn it back into a string before returning
Markus Kiili
@Masd925
Jul 07 2016 06:58
@JonathonLLopez You can just return the joined array (it is a string).
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 06:59
@Masd925 I see. Making it a variable allowed to return it. Thanks guys. @Athaman
CamperBot
@camperbot
Jul 07 2016 06:59
jonathonllopez sends brownie points to @masd925 and @athaman :sparkles: :thumbsup: :sparkles:
:star2: 2066 | @masd925 |http://www.freecodecamp.com/masd925
Athaman @Athaman sneaks in for brownie points
Mostafa Syam
@pro-mos
Jul 07 2016 07:05
This message was deleted
Ayush Sharma
@a-y-u-s-h
Jul 07 2016 07:07
Where can I learn about meaning and use of prototype word used every now and then? something.prototype.somethingElse
@bonhokage06
Jul 07 2016 07:08
hi
i forgot how to add code in this chatbox?
Keone Martin
@Athaman
Jul 07 2016 07:09
help format
CamperBot
@camperbot
Jul 07 2016 07:09

# Multi line Code

js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

 ⇦ Type 3 backticks, then press [enter ⏎]

# Single line Code

This an inline <paste code here> code formatting with a single backtick() at _start_ and _end_ around thecode.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

Keone Martin
@Athaman
Jul 07 2016 07:09
@bonhokage06 ^
@bonhokage06
Jul 07 2016 07:09
'''
CamperBot
@camperbot
Jul 07 2016 07:09
:bulb: to format code use backticks!  more info
Keone Martin
@Athaman
Jul 07 2016 07:10
backtick not ' should be left of the 1 on a US keyboard
@bonhokage06
Jul 07 2016 07:10

function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var srcKeys=Object.keys(source);
collection.forEach(function(item,index){
srcKeys.forEach(function(srcItem,srcIndex){
if(item.hasOwnProperty(srcItem)){
var value=item[srcItem];
var srcValue=source[srcItem];
if(value===srcValue){
}
}
else{
}
});
arr.push(item);
}
});
// Only change code above this line
return arr;
}
kindly check my solution for this.
Ayush Sharma
@a-y-u-s-h
Jul 07 2016 07:10
@Athaman Thanks
CamperBot
@camperbot
Jul 07 2016 07:10
a-y-u-s-h sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
Jul 07 2016 07:10
no problem @a-y-u-s-h
@bonhokage06 what's the challenge name?
@bonhokage06
Jul 07 2016 07:11
@Athaman Wherefore art thou
@Athaman thanks man
CamperBot
@camperbot
Jul 07 2016 07:11
bonhokage06 sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Markus Kiili
@Masd925
Jul 07 2016 07:12
@Athaman W3Schools is good site, but their javascript content is bad.
Keone Martin
@Athaman
Jul 07 2016 07:12
it's less technical than a lot of other resources... but it's also less intimidating
x981
@x981
Jul 07 2016 07:13
@coymeetsworld https://www.twitch.tv/esl_sc2 I can not load content of page in FireFox
NixonRichard
@NixonRichard
Jul 07 2016 07:14
wow star craft
i still have brood war in my computer
Keone Martin
@Athaman
Jul 07 2016 07:14
oldschool
x981
@x981
Jul 07 2016 07:14
So i don't understand what i have to do
NixonRichard
@NixonRichard
Jul 07 2016 07:15
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
if ( value === '')
{delete collection[id][prop];}
else if (prop != "tracks" && value !== ''){
return collection[id][prop].push(value);
}else if (prop == 'tracks' && collection[id][prop] === ''){
collection[id][prop] = []; collection[id][prop] .push(value);
}else if (prop == 'tracks' && value !== ''){
return collection[id][prop].push(value);
}}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Keone Martin
@Athaman
Jul 07 2016 07:15
@bonhokage06 looks legit, it seems about the way i went about it.
NixonRichard
@NixonRichard
Jul 07 2016 07:15
fix my code thx alot
cant read property 'push' of undefined

You are given a JSON object representing a part of your musical album collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.

Write a function which takes an album's id (like 2548), a property prop (like "artist" or "tracks"), and a value (like "Addicted to Love") to modify the data in this collection.

If prop isn't "tracks" and value isn't blank, update or set the value for that record album's property.

Your function must always return the entire collection object.

There are several rules for handling incomplete data:

If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.

If prop is "tracks" and value isn't blank, push the value onto the end of the album's existing tracks array.

If value is blank, delete that property from the album.

Hints
Use bracket notation when accessing object properties with variables.

Vikash Saini
@Enigma10
Jul 07 2016 07:19
CamperBot
@camperbot
Jul 07 2016 07:19
Markus Kiili
@Masd925
Jul 07 2016 07:20
@Athaman For example that prototype page in W3Schools is full of total rubbish.
Keone Martin
@Athaman
Jul 07 2016 07:20
@NixonRichard you should use collection[id].hasOwnProperty(prop) not collection[id][prop] === '') the array not existing will fail that gate
@Masd925 yeah? it looked ok... you have prototypes, things inherit from the prototypes
NixonRichard
@NixonRichard
Jul 07 2016 07:22
still fail
lol\
Vikash Saini
@Enigma10
Jul 07 2016 07:22
Keone Martin
@Athaman
Jul 07 2016 07:22
sorry, i've got an assignment due so i can't spend much time on it @NixonRichard
NixonRichard
@NixonRichard
Jul 07 2016 07:22
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
if ( value === '')
{delete collection[id][prop];}
else if (prop != "tracks" && value !== ''){
return collection[id][prop].push(value);
}else if (prop == 'tracks' && collection[id].hasOwnProperty(prop)){
collection[id][prop] = []; collection[id][prop] .push(value);
}else if (prop == 'tracks' && value !== ''){
return collection[id][prop].push(value);
}}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
nevermine @Athaman
Keone Martin
@Athaman
Jul 07 2016 07:25
you also have a space between collection[id][prop] and .push(value)
Markus Kiili
@Masd925
Jul 07 2016 07:25
@Athaman For starters:
"Every JavaScript object has a prototype. The prototype is also an object." - can have a prorotype
"The constructor function is the prototype for Person objects." - No, constructor and prototype of an object are not the same thing.
"You cannot add a new property to a prototype the same way as you add
a new property to an existing object, because the prototype is not an existing object." - it is and you can.
NixonRichard
@NixonRichard
Jul 07 2016 07:26
not working
@Masd925 for me ?
Keone Martin
@Athaman
Jul 07 2016 07:26
oh... ok then. those bits do sound rubbish
96street
@96street
Jul 07 2016 07:26
@Masd925 just had a break here's where i was:
 var arr = [];
for(var objs in collection)  {
for(var srcKeys in source) {
if(collection[objs]==source[srcKeys]) {
// push
}
}
}
Keone Martin
@Athaman
Jul 07 2016 07:26
i'll look for a better resource another time ;)
Markus Kiili
@Masd925
Jul 07 2016 07:27
@Athaman Thanks ;)
CamperBot
@camperbot
Jul 07 2016 07:27
masd925 sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
96street
@96street
Jul 07 2016 07:27
you said: You are not accessing looped objects property value.
Vikash Saini
@Enigma10
Jul 07 2016 07:27
CamperBot
@camperbot
Jul 07 2016 07:27
96street
@96street
Jul 07 2016 07:27
@Masd925
Markus Kiili
@Masd925
Jul 07 2016 07:27
@96street Yes, you are not.
96street
@96street
Jul 07 2016 07:27
would .value give that?
Markus Kiili
@Masd925
Jul 07 2016 07:28
@96street Use [srcKeys]
96street
@96street
Jul 07 2016 07:28
i am?
Markus Kiili
@Masd925
Jul 07 2016 07:28
Better name it key than keys.
@96street On left side too.
lego james
@fireworkNext
Jul 07 2016 07:28
how can i close the notify?
NixonRichard
@NixonRichard
Jul 07 2016 07:28
it s not working
my code zzz
Vikash Saini
@Enigma10
Jul 07 2016 07:29
@NixonRichard Check your second and third condition .
96street
@96street
Jul 07 2016 07:29
@Masd925 why does it matter if its on the left side?
var arr = [];
for(var objs in collection)  {
for(var srcKey in source) {
if(source[srcKey]==collection[objs]) {
// push
}
}
}
did it anyway
Markus Kiili
@Masd925
Jul 07 2016 07:30
@96street You are comparing the looped object with the property value in source. Always false.
96street
@96street
Jul 07 2016 07:30
ahh ok
so i need to go deeper in collection[objs]?
wouldn't that mean another for loop?
Markus Kiili
@Masd925
Jul 07 2016 07:31
@96street No, just use [srcKeys] to access the property on the looped object.
96street
@96street
Jul 07 2016 07:32
can't srcKeys only access the source object?
Markus Kiili
@Masd925
Jul 07 2016 07:32
@96street It is a string.
96street
@96street
Jul 07 2016 07:32
its only looping source
ahh right
Markus Kiili
@Masd925
Jul 07 2016 07:33
@96street It is a property key. You can access looped objects property with that key also.
@bonhokage06
Jul 07 2016 07:33


function myReplace(str, before, after) {
var firstLetter=before.substring(0,1);
if(firstLetter===firstLetter.toUpperCase()){
after=after.charAt(0).toUpperCase() + after.slice(1);
}
return str.replace(before,after);
}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
kindly check my solution for this excercise.
NixonRichard
@NixonRichard
Jul 07 2016 07:34
i dont know what s wrong with my second and third condition
Mostafa Syam
@pro-mos
Jul 07 2016 07:35
how to check an argument if its blank or not?
Markus Kiili
@Masd925
Jul 07 2016 07:35
@pro-mos Empty string you mean?
Mostafa Syam
@pro-mos
Jul 07 2016 07:36
yes
Markus Kiili
@Masd925
Jul 07 2016 07:36
@pro-mos str==="" or str.length===0
NixonRichard
@NixonRichard
Jul 07 2016 07:36
use for loop
Graveworm
@legyolo
Jul 07 2016 07:36
hello there! what is wrong with my code? maybe it is a b*llshit :)
// Check if the user is ready to play!
var txt;
var choose = confirm(Are you ready to play?);
if (choose===true) {
console.log (txt="ok");
}
else {
console.log (txt="cancel");
}
Mostafa Syam
@pro-mos
Jul 07 2016 07:37
ok thanks
NixonRichard
@NixonRichard
Jul 07 2016 07:37
hmm
96street
@96street
Jul 07 2016 07:39

so just to clear it up, collection[objs] could be: { first: "Romeo", last: "Montague" }

and source[srcKey] could be: last

@Masd925

going by this test:

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

Markus Kiili
@Masd925
Jul 07 2016 07:39
@96street Not last but "Capulet"
because you access the property value with syntax obj[key]
Value of srcKey is "last"
Jonathan Mitchell
@Vanhealen
Jul 07 2016 07:42
yo
so I have an array filled with a ton of objects and I want to dynamically create a modal when a certain dom element is clicked. What is a good library to do this with?
Vikash Saini
@Enigma10
Jul 07 2016 07:42
@NixonRichard try this
function updateRecords(id, prop, value) {

if(value !== ""){
if(prop == "album" || prop == "artist" )
collection[id][prop]=value;
else if(prop == "tracks"){
collection[id][prop].push(value);
}}
else delete collection[id][prop];

return collection;
}
Jonathan Mitchell
@Vanhealen
Jul 07 2016 07:42
I dont want the model to appear in html when the dom element hasnt been clicked
96street
@96street
Jul 07 2016 07:43
@Masd925 so what would the whole object be? : { last: "Capulet" }
Markus Kiili
@Masd925
Jul 07 2016 07:43
value of parameter source
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 07:45
Can someone explain factoralizing with recursion function?
96street
@96street
Jul 07 2016 07:45
ok now i get it
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 07:46
I'm on a challenge that wants me to factorlize(num) and I've never even seen this before, so I looked it up and apparently using recursion is the best way to do it
Vikash Saini
@Enigma10
Jul 07 2016 07:46
@NixonRichard
function updateRecords(id, prop, value) {

if(value === ""){
delete collection[id][prop];
}
else
{
if(prop!== "tracks")
collection[id][prop]=value;
else {
collection[id][prop].push(value);
}}
return collection;
}
Markus Kiili
@Masd925
Jul 07 2016 07:46
@JonathonLLopez For loop is fine too. Good spot to learn recursion though.
96street
@96street
Jul 07 2016 07:47
when you say: you access the property value with syntax obj[key]
what would be the equivilent to my test @Masd925 @Masd925
Markus Kiili
@Masd925
Jul 07 2016 07:48
@96street You have to use the same source key and access both the looped object and source, and compare the values that you get.
So use [srcKey] on both sides of comparison.
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 07:49
@Masd925 okay sounds easier, but still, what exactly is factoralizing?
Markus Kiili
@Masd925
Jul 07 2016 07:50
@JonathonLLopez Multiplying all positive integers up to the given number.
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 07:57
@Masd925 thanks for clarifying. This is what I came up with:
function factorialize(num) {
var n = 1;
for (var i = 1; i <= num; i++) {
n *= i;
}
return n;
}

factorialize(5);
CamperBot
@camperbot
Jul 07 2016 07:57
jonathonllopez sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: jonathonllopez already gave masd925 points
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 07:58
So, what would a recursive version of this look like?
Jonathan Mitchell
@Vanhealen
Jul 07 2016 07:58
how do I add <a href=“#”> attributes into an element in jquery
Markus Kiili
@Masd925
Jul 07 2016 07:59
@JonathonLLopez The function first had to check if num===0 and return 1. On other cases it would return num*factorialize(num-1).
So it would make a call to the same function with a smaller argument. Eventually the chain of function calls hits num===0 and all the calls get resolved.
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 08:00
@Masd925 okay num * factoralize(num-1)? Holy crap.
Mustafijur rahman
@Dinar717
Jul 07 2016 08:01
:warning: lol :warning:
Markus Kiili
@Masd925
Jul 07 2016 08:02
That is because 5! = 5 * 4 * 3 * 2 * 1 is the same as 5*(4*3*2*1) which is 5* 4! (<- I denote factorization with ! here)
So you can always calculate factorial by calculating a smaller factorial.
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 08:04
@Masd925 which is where num - 1 comes from, right?
Markus Kiili
@Masd925
Jul 07 2016 08:04
@JonathonLLopez Yes.
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 08:05
@Masd925 so it would iterate through each time, multiplying it by num, until it reached num
Mostafa Syam
@pro-mos
Jul 07 2016 08:07
I'm stuck at Record Collection :worried:

// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
if (value === "") {
delete collection[id][prop];

} else if (prop !== "tracks" && value !== "") {
collection[id][prop] = value;

} else if (prop === "tracks") {
if (!collection.hasOwnProperty("tracks")) { // if there is no tracks property, make it
collection[id].tracks = [];
}

if (value !== "") {
collection[id].tracks.push(value);
}
}

return collection;
}
Stas
@mastas3
Jul 07 2016 08:08
@JonathonLLopez here's a nice graphic explanation of recursion http://www.mrlamont.com/uploads/1/7/0/2/17021682/factorial.png
willfree108
@willfree108
Jul 07 2016 08:09
This message was deleted
Stas
@mastas3
Jul 07 2016 08:09
As you can see, the function keeps calling itself until it reaches its "base case", which is num==1 and then it returns all the way back to the beginning
willfree108
@willfree108
Jul 07 2016 08:10
@pro-mos which test do u fail ?
Markus Kiili
@Masd925
Jul 07 2016 08:10
@JonathonLLopez So the execution of factorialize(5) involves a call to factorialize(4) which involves a call to factorialize(3) etc until the last factorialize(0) evaluates to 1 and all the calls get resolved.
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:10
A recursive function must have a stopping potential, otherwise, it overflows the stack and moves out of the browser and plays with CPU
Mostafa Syam
@pro-mos
Jul 07 2016 08:11
updateRecords(2468, "tracks", "Free") it removes other tracks from the array and adds "Free"
@willfree108
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:13
I think now we're having recursion with the way we help each other
• Camper A asks for help
• Camper B asks for help and also helps camper A
• Camper C helps camper B
• Camper A thanks Camper B for helping them
• Camper B thanks Camper C for helping them
• Camper A, B and C are happy and return home :blush:
Stas
@mastas3
Jul 07 2016 08:14
😁
Mostafa Syam
@pro-mos
Jul 07 2016 08:14
fixed it.
Markus Kiili
@Masd925
Jul 07 2016 08:15
@abhisekp Yes, and if we indeed live inside a simulation done by some advanced civilization, we should fear doing any heavy calculations that can crash the simulation. So efficiency is of essence.
willfree108
@willfree108
Jul 07 2016 08:15
@pro-mos ur forget id on a collection somewhere
Ramesh syangtan
@rameshsyn
Jul 07 2016 08:15
@mastas3 :D Thanks ! helpful :D graphic explanation of recursion
CamperBot
@camperbot
Jul 07 2016 08:15
rameshsyn sends brownie points to @mastas3 :sparkles: :thumbsup: :sparkles:
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 08:16
@Masd925 @mastas3 I see. I'm starting to understand it. I ran this code through, but it says factorialize(0) isn't returning 1. Why is that?

function factorialize(num) {
if (num <= 1) {
return num;
} else {
return num * factorialize(num - 1);
}
}
factorialize(0);
Mostafa Syam
@pro-mos
Jul 07 2016 08:16
@willfree108 yes i figured it out :D thanks
CamperBot
@camperbot
Jul 07 2016 08:16
pro-mos sends brownie points to @willfree108 :sparkles: :thumbsup: :sparkles:
Markus Kiili
@Masd925
Jul 07 2016 08:16
@JonathonLLopez if (num===0) return 1; would work.
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:16
@Masd925 wat if the advanced civilization is using pm2 or forever or nodemon for process processing and mgmt :P
Jonathon Lopez
@JonathonLLopez
Jul 07 2016 08:17
@Masd925 that's fair. I guess you could make it very specific lol
ahmed abouhay
@abohay
Jul 07 2016 08:18

@abhisekp
// Setup
var myStorage = {
"car": {
"car": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = myStorage.car.car["glove box"];// Change this line

Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:19
// Setup
var myStorage = {
"car": {
"car": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = myStorage.car.car["glove box"];// Change this line
@abohay umm.. looks rt.. wats the issue?
ahmed abouhay
@abohay
Jul 07 2016 08:20
doesn't pass the challenge it give the result
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:20
@abohay whc challenge if u may?
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:22

@abohay the instruction

Access the myStorage object and assign the contents of the glove box property to the gloveBoxContents variable. Use bracket notation for properties with a space in their name.

reset the challenge and try to solve again
ur object in the code isn't correct @abohay
the one u showed is different than the one provided
ahmed abouhay
@abohay
Jul 07 2016 08:24
@abhisekp thanks
CamperBot
@camperbot
Jul 07 2016 08:24
abohay sends brownie points to @abhisekp :sparkles: :thumbsup: :sparkles:
:star2: 2644 | @abhisekp |http://www.freecodecamp.com/abhisekp
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:29

### Random Quiz 101-11

Q: What is the value of 5**2**2 (mental calculation)
ahmed abouhay
@abohay
Jul 07 2016 08:29
** @abhisekp ?
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:30
@abohay exponent operator
$10^2=100$
10 ** 2 = 100
Math.pow(10, 2) // 100
Carlos Ortega
@zorudeam
Jul 07 2016 08:33
2525... = 2520 +255 -> 500+255-> 500+125 -> 625
Mostafa Syam
@pro-mos
Jul 07 2016 08:34
or you could simply say 2 +2 = 4, then 5 ^ 4
kirbyedy
@kirbyedy
Jul 07 2016 08:39
@abhisekp :ghost:
Carlos Ortega
@zorudeam
Jul 07 2016 08:44
I'm stuck in JavaScript Record Collection, second assignment
Gleb Sabakarov
@Glebasty1
Jul 07 2016 08:44
Hello guys can someone HELP me out with this challenge,i rly cant understand(
Record Collection
Carlos Ortega
@zorudeam
Jul 07 2016 08:44
I have
collection[id][prop].push(value); but it seems that does not work
Gleb Sabakarov
@Glebasty1
Jul 07 2016 08:45
Carlos Ortega
@zorudeam
Jul 07 2016 08:46
@Glebasty1 I'm also stuck there, I copied from an online website because understanding that was taking forever, but a line from that doesn't work, and I don't know why
Keone Martin
@Athaman
Jul 07 2016 08:46
@zorudeam have you checked that the collection[id][prop] exists?
Carlos Ortega
@zorudeam
Jul 07 2016 08:46
Uhm, no
:'v I'll just try that
Keone Martin
@Athaman
Jul 07 2016 08:46
use .hasOwnProperty() on collection[id] to check before you push to it, and make an empty array if it doesn't exist :)
Carlos Ortega
@zorudeam
Jul 07 2016 08:47
Wait
how do I make an empty array in JS?
Keone Martin
@Athaman
Jul 07 2016 08:47
collection[id][prop] = [];
Abhisek Pattnaik
@abhisekp
Jul 07 2016 08:47

@zorudeam @pro-mos umm... the evaluation is something like this

5**2**2

1. 5**(2**2)
2. 5**4
3. 625`
Carlos Ortega
@zorudeam
Jul 07 2016 08:47
Ok!
Keone Martin
@Athaman
Jul 07 2016 08:47
well, more generally var name = [];
Carlos Ortega
@zorudeam
Jul 07 2016 08:50
uhh now its worse. I wrote this: else if (prop == "tracks"){
if(!collecion[id].hasOwnProperty(prop)){
collection[id][prop] = [];
}
collection[id][prop].push(value);
}
Keone Martin
@Athaman
Jul 07 2016 08:51
hmm... that should be right.
send the full code?
Carlos Ortega
@zorudeam
Jul 07 2016 08:52
if (value === '') {
delete collection[id][prop];
} else if (prop !== 'tracks') {
collection[id][prop] = value;
} else if (prop == "tracks"){
if(!collecion[id].hasOwnProperty(prop)){
collection[id][prop] = [];
}
collection[id][prop].push(value);
}
this is mostly from a website I found, since I was also stuck with understanding the assingment
Jordan Mizrachi
@jmizrachi
Jul 07 2016 08:53
Thanks @CaroleAnneHannon for your help with Checkpoint: Stand in Line
CamperBot
@camperbot
Jul 07 2016 08:53
jmizrachi sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles: