Created
July 12, 2017 10:15
-
-
Save morisasy/181aa01012a27419068fb00cf41b803f to your computer and use it in GitHub Desktop.
selectfunction
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 "select". | |
Given an array and an object, "select" returns a new object whose properties are those in the given object AND whose keys are present in the given array. | |
Notes: | |
* If keys are present in the given array, but are not in the given object, it should ignore them. | |
* It does not modify the passed in object. | |
function select(arr, obj) { | |
// create an empty obj | |
var output = {}; | |
// forEach return array value; | |
arr.forEach(function(data){ | |
for(var key in obj){ | |
if(key == data) { | |
output[key] = obj[key]; | |
} | |
} | |
}); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment