Skip to content

Instantly share code, notes, and snippets.

@troyleach
Created March 27, 2015 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troyleach/9e5bfe6b421b094fb1da to your computer and use it in GitHub Desktop.
Save troyleach/9e5bfe6b421b094fb1da to your computer and use it in GitHub Desktop.
find words greater than i
// Write a function filterLongWords() that takes an array of words and an integer i and returns the array of words
// that are longer than i. (if I understand what they are asking for)..
// also, why when I use << - this syntax doesn't work but the .push does?? I thought they both would work?
var i = 5
var wordsGreaterThan = []
function filterLongWords(source) {
var sentence = source.split(/\s/);
for ( var j = 0; j < sentence.length; j++) {
if (sentence[j].length > i) {
wordsGreaterThan.push(sentence[j]);
}
}
return wordsGreaterThan;
}
console.log(filterLongWords("find the longest word in this phase please"));
var numberOfWords = 2
console.log(numberOfWords === wordsGreaterThan.length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment