Created
July 12, 2017 09:02
-
-
Save morisasy/1868bca09e4c433922f5c866d28490bc to your computer and use it in GitHub Desktop.
get elements that equal to 10th at property
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 called "getElementsThatEqual10AtProperty". | |
Given an object and a key, "getElementsThatEqual10AtProperty" returns an array containing all the elements of the array located at the given key that are equal to ten. | |
Notes: | |
* If the array is empty, it should return an empty array. | |
* If the array contains no elements equal to 10, 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 key, it should return an empty array. | |
function getElementsThatEqual10AtProperty(obj, key) { | |
// your code here | |
var array = []; | |
//check if obj[key] is true | |
if(obj[key]){ | |
// looping through an obj. | |
for(var i in obj[key]){ | |
// testing if obj value is 10 | |
if(obj[key][i]== 10){ | |
array.push(obj[key][i]); | |
} | |
} | |
return array; | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks this was helpful.