Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var myEach = require('./myEach');
var myMap = require('./myEach');
var myReduce = require('./myEach');
var myMap = require('./myMap');
var myReduce = require('./myReduce');
/* *********************************************************************
You can edit this file
It will make use of your code in myEach.js, myMap.js and myReduce.js
Expand All @@ -10,6 +10,13 @@ var myReduce = require('./myEach');
var numArray = [0,1,10,100,1000];


// function myEach(callback, i, array) {
// for(var i = 0; i < array.length; i++) {
// callback(array[i]);
// }
// };


/* myEach */

//
Expand All @@ -18,6 +25,10 @@ var numArray = [0,1,10,100,1000];
// });


var singleNumArray = [50,60,70,80];
var doubleNumArray = myMap(arrIndex, function(num, numIndex, originalArry) {
return num * 2;
});


/* myMap */
Expand Down
10 changes: 7 additions & 3 deletions myEach.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ForEach
function callback() {
console.log();
}

function myEach(arr, callback) {

// CODE INSIDE HERE //

}
for(var i = 0; i < arr.length; i++) {
callback(arr[i], i, arr);
}
};

/*
Best if you don't code out here.
Expand Down
9 changes: 6 additions & 3 deletions myMap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Map

function myMap(arr, callback) {
var newNumArray = [];

// CODE INSIDE HERE //

}
for(var i = 0; i < arr.length; i++) {
newNumArray.push(callback(arr[i], i, arr));
}
return newNumArray;
};

/*
Best if you don't code out here.
Expand Down
13 changes: 11 additions & 2 deletions myReduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
// Don't worry about initialValue at first. You can always add it in later.

function myReduce(arr, callback) {

// CODE INSIDE HERE //
var reducedValue;
for(var i = 0; i < arr.length; i++) {
reducedValue.push(callback);
}

}

/*

I did not get very far into this one, but it's already 12:30 pm... gotta get some sleep!
I plan on working on this before class tommorrow, and will get help from a TA if needed.

*/

/*
Best if you don't code out here.
If you want to check your code, use `index.js`!
Expand Down