DEV Community

Discussion on: Daily Challenge #60 - Find the Missing Letter

Collapse
 
rdelga80 profile image
Ricardo Delgado • Edited

This my solution, I also tried to account for the possibility that there wasn't just one letter missing:

checkChar = array => {
    const missing = []

    for(let i = 1; i < array.length; i++) {
        var firstLet = array[i].charCodeAt(0)
        var prevLet = array[i - 1].charCodeAt(0)
        if (firstLet - prevLet > 1) missing.push([firstLet, prevLet])
    }

    return missing.map(letterArray => {
        const letters = []

        for(let i = letterArray[1] + 1, c = 0; c < (letterArray[0] - letterArray[1] - 1); c++) {
            letters.push(String.fromCharCode(i))
            i++
        }
        return letters
    })[0]
}