Hey guys, I’m stuck, my code work and do what is asked but still does not fulfill the fourth condition, anyone know why ?
function frankenSplice(arr1, arr2, n) {
let arr2fonc = arr2.slice();
for (let i = 0; i < n; i++){
if (i = n){
//for (let j = 0; j < 1; j++){
arr2fonc.splice(n,0, arr1)
//}
}
}
return arr2fonc.flat()
}
console.log(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36
Challenge: Slice and Splice
Link to the challenge:
yeah I don’t understand why, but I’m sure that you don’t need that for
loop
ilenia
3
here you are assigning the value of n
to the variable i
so the question is why does it work?
ilenia
5
because splice
does not depend from i
in the code
yeah but why the condition results true
?
ilenia
7
it depends on the value of n
, if it’s 0
then it doesn’t execute beause it is falsy, any other number is truthy so the if condition is executed
1 Like
right, thanks for the clarification
system
Closed
9
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.