Hello! I passed the challenge but looking at my code, It’s really hideous.
Do you guys have any tips or suggestions on what to do or how I should go about with this and my future codes?
Your code so far
function whatIsInAName(collection, source) {
let retArr = [];
let retArr2 = [];
for (let key in source){
for (var x = 0; x < collection.length; x++){
if (collection[x].hasOwnProperty(key) && collection[x][key] === source[key]) {
if(retArr.includes(collection[x])){
}
else{
retArr.push(collection[x]);
console.log(retArr);
}
}
}
break;
}
let count = 0
for (let key in source){
if (count === 1){
console.log("retarr", retArr)
console.log(key, count)
for (var x = 0; x<retArr.length; x++){
if (retArr[x].hasOwnProperty(key) && retArr[x][key] === source[key]) {
retArr2.push(retArr[x]);
console.log(retArr2);
}
}
count++;
break;
}
count++ ;
}
if (count === 1) {
return retArr;
}
return retArr2;
}
whatIsInAName([{ "apple": 1 }, { "apple": 1 }, { "apple": 1, "bat": 2 }], { "apple": 1 });
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
.
Challenge: Wherefore art thou
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/wherefore-art-thou