Created
March 27, 2015 22:24
-
-
Save troyleach/9e5bfe6b421b094fb1da to your computer and use it in GitHub Desktop.
find words greater than i
This file contains 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 characters
// 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