I'm attempting to check the array for the same data types using a for loop and if conditionals. However, my code doesn't seem to be working as expected. Can someone please help me figure out why?
Thank you in advance!
function checkDataTypes(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(checkDataTypes([1, 1, "string"]))