Skip to content

Instantly share code, notes, and snippets.

@alphabet
Created December 20, 2018 15:18
Show Gist options
  • Save alphabet/611e1b4491c3e5744c618e89cd626786 to your computer and use it in GitHub Desktop.
Save alphabet/611e1b4491c3e5744c618e89cd626786 to your computer and use it in GitHub Desktop.

Revisions

  1. alphabet created this gist Dec 20, 2018.
    20 changes: 20 additions & 0 deletions typeAhead.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    // Given an array of words, create a read-ahead method //

    /************************************************************/
    var myClass = {};

    myClass.words = [ 'hippo', 'heckle', 'hamster', 'porcelain', 'potato', 'pompom', 'party'];

    myClass.words.sorted = myClass.words.sort();

    myClass.filter = (char) => {
    return myClass.words.sorted.filter(
    function(word){
    return word.indexOf(char)===0;
    }
    );
    }
    /************************************************************/

    // usage: returns all words starting with string 'ham'
    myClass.filter('ham');