Day 10 of 30 of Codewars – Javascript

I’ve challenged myself to 30 days of codewars, one a day, time myself, and learn how I could have done it better.

Today I did: https://www.codewars.com/kata/5839edaa6754d6fec10000a2

Time: 25 minutes

What I’ve learnt: This one I did in my weekly javascript study group with a few coding buddies. I love doing kata together as we get to discuss different ideas together 🙂

We used functions we have all used in the past to achieve this solution, inside our for loop. Nothing too new this time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function findMissingLetter(array) {
  let nextLetter = 0;
  
  for (let i = 0; i < array.length - 1; i++) {
    let currentLetter = array[i].toLowerCase().charCodeAt();
    nextLetter = array[i + 1].toLowerCase().charCodeAt();
      
    if (nextLetter && nextLetter !== currentLetter + 1) {
      return String.fromCharCode(array[i].charCodeAt() + 1 )
    }
  }
}

 

What I learned from other people’s code:
Although not required from the kata, I like it how someone used

throw new Error(“Invalid input”)

The sound of that function totally matches what it does! It’s awesome!

Otherwise I feel people have reached their solution similarly to ours. I do like MaximumJoe’s one line solution using reduce. Gotta start reducing too!

Until tomorrow!

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright Loving to Code 2025
Tech Nerd theme designed by Siteturner