Problem with expected solutions can be found here : https://www.codewars.com/kata/58287977ef8d4451f90001a0/train/javascript
I have played around with console results and can see that whatever I set as my variable in the 2nd line of code let allSame = true;
is what the end result returns. As I understand the for loop HAS to play out and so the IF statement then MUST play out - So one way or the other the variables should be updated. Maybe I have missed something out when it comes to global/local variables?
Please include an explanation with answer as I am trying to learn -- Thanks!
function isSameLanguage(list) {
let allSame = true;
for(let i = 0; i<list.length-2; i++)
if(list[i]["language"] == list[i+1]["language"]){
let allSame = true;
}else{
let allSame = false;
}
return allSame;
}