mercredi 23 octobre 2019

Why is the for loop with a conditional not iterating all the way to the end of the array?

I am writing a function to change the letters in a string (to camelCase) and the dashes and underscores are used as markers for the end of a word. I want to know why my for loop is stopping before it reaches the end of the array, especially since the conditional code isn't being used.

I've tried console logging my tmp array and it has what I want in it (the '_' or '-'). But the code seems to mess up after the conditional so I'm thinking it has something to do with that.

for (let letter of arr) {
  arr.pop(letter)
  if (letter === '-' || letter === '_') {
    let tmp = []
    tmp.push(letter)
    console.log(tmp)
  } else {
    camelArr.push(letter)
    console.log(camelArr)
  }
}

Aucun commentaire:

Enregistrer un commentaire