This file contains hidden or 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
//PART 1 | |
//Debug each: You are given this function each, but it doesn't work exactly as expected. | |
/*It should call callback on value, key, and collection respectively for each element of collection, | |
and accept both arrays and objects. Identify everything incorrect with each as it is provided, | |
and modify the function so that it works as expected. Be sure to list all that was incorrect about the original function. */ | |
var each = function(collection, callback) { | |
if (typeof collection === "array"){ | |
for (var i = 0; i < collection.length; i++) { | |
callback(collection[i], i, collection); | |
} |