Created
July 12, 2017 14:18
-
-
Save morisasy/4a593a35bd1074ba37224e4c9934dbba to your computer and use it in GitHub Desktop.
Given an object and a key, write a function "getNthElementOfProperty" returns the nth element of an 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 undefined. | |
* If n is out of range, it should return undefined. | |
* If the property at the given key is not an array, it should return undefined. | |
* If there is no property at the key, it should return undefined. | |
function getNthElementOfProperty(obj, key, n) { | |
// your code here | |
if ( Array.isArray( obj[key] ) === false ){ | |
return undefined; | |
}else if ( obj[key][0] === undefined){ | |
return undefined; | |
}else{ | |
return obj[key][n]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment