Created
July 12, 2017 18:00
-
-
Save morisasy/8cd65bc8a91633057b6b1470b3f3a080 to your computer and use it in GitHub Desktop.
Given an object and a key, create a function "getOddLengthWordsAtProperty" returns an array containing all the odd length word elements of the array located at the given key.
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
Notes: | |
* If the array is empty, it should return an empty array. | |
* If it contains no odd length elements, it should return an empty array. | |
* If the property at the given key is not an array, it should return an empty array. | |
* If there is no property at the given key, it should return an empty array. | |
function getOddLengthWordsAtProperty(obj, key) { | |
// your code here | |
if (obj[key] === undefined || Array.isArray(obj[key]) === false || obj[key].length === 0) { | |
return []; | |
} | |
var output =obj[key].filter(function(element) { | |
return element.length % 2 !== 0; | |
}); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment