Skip to content

Instantly share code, notes, and snippets.

View AlejandroRodriguezP's full-sized avatar

Alejandro Rodriguez AlejandroRodriguezP

View GitHub Profile
//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);
}