I have a function resFormat(restrictions)
which takes an array of restrictions as a parameter and returns a string which contains diet restrictions. When calling it with ["res1","res2","res3"]
, it should return "res1, res2, res3"
function resFormat(restrictions){
let result="",i
for (i in restrictions){
if(i===restrictions.length-1){ //always returns false
result += restrictions[i]
continue
}
result += restrictions[i]+", "
}
return result
}
console.log(resFormat(["res1", "res2", "res3"]));
Here i===restrictions.length-1
should return true when the loop reaches the last element of the array, but it always returns false.
Expected output:
res1, res2, res3
Actual output:
res1, res2, res3,