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.
// 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment