Skip to content

Instantly share code, notes, and snippets.

@morisasy
Created July 12, 2017 10:15
Show Gist options
  • Save morisasy/181aa01012a27419068fb00cf41b803f to your computer and use it in GitHub Desktop.
Save morisasy/181aa01012a27419068fb00cf41b803f to your computer and use it in GitHub Desktop.
selectfunction
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