Skip to content

Instantly share code, notes, and snippets.

Created December 6, 2015 06:36

Revisions

  1. @invalid-email-address Anonymous created this gist Dec 6, 2015.
    26 changes: 26 additions & 0 deletions bonfire-missing-letters#.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    // Bonfire: Missing letters
    // Author: @dannycoder
    // Challenge: http://www.freecodecamp.com/challenges/bonfire-missing-letters#
    // Learn to Code at Free Code Camp (www.freecodecamp.com)

    function fearNotLetter(str) {

    //detect if the letter is missing
    if(str.length === (str.charCodeAt(str.length - 1) - str.charCodeAt(0) + 1 )){

    return undefined;

    } else {

    //track down the missing letter
    for(var i = str.charCodeAt(0), j = 0; i <= str.charCodeAt(str.length -1); i++, j++) {

    //return the missing letter
    if(String.fromCharCode(str.charCodeAt(j)) !== String.fromCharCode(i)) {
    return String.fromCharCode(i);
    }
    }
    }
    }

    fearNotLetter("abce");