Okay, the problem asks me to update a string. When the char is followed by an A, I callback my addOne function and delete the A. When my char is followed by a B, I callback my subtractOne function and delete the B. Here is what I have, and my test variable - 123A456B should return 124455. Instead it returns 1231455. Can someone help me figure out why? I feel like I am missing something obvious. Thank you!
const test = '123A456B'
function addOne(num) {
return num + 1
}
function subtractOne(num) {
return num - 1
}
function updateString(string) {
let result = ''
for (let i = 0; i < string.length; i++) {
if (string[i] === 'A' || string[i] === 'B') {
} else if (string[i + 1] === 'A') {
result += addOne(string[i])
} else if (string[i + 1] === 'B') {
result += subtractOne(string[i])
} else result += string[i]
}
return result
}
console.log(updateString(test))