i want to check the array for the same datatypes. i found other solutions here but i want to do it with for loop and if conditonals. Can someone please explain, why my code is not working:
thank you very much!
function sameDataType(array){
const helper = []
for(let i = 0; i < array.length; i++){
let dataType0 = typeof(array[i])
let dataType1 = typeof(array[i+1])
if(dataType0 === dataType1){
helper.push(1)
} else {
helper.push("not")
}
}
for(let j = 0; j < helper.length; j++){
if(helper[j] === helper[j+1]){
return "same"
} else {
return "different"
}
}
}
console.log(sameDataType([1, 1, "string"]))