Created
December 20, 2018 15:18
-
-
Save alphabet/611e1b4491c3e5744c618e89cd626786 to your computer and use it in GitHub Desktop.
Revisions
-
alphabet created this gist
Dec 20, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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');