// All three avoids mutation of the original array
// Map()
const arr = [1, 2, 3, 4];
// takes in the value, the index, and the array itself
const arrTimesTwo = arr.map((value, index, arr) => {
return value * 2;
});
// Filter()
// Filter receives the same arguments as map()
// The only difference is the callback needs to return either true or false
const names = ["chase", "john", "jacob", "diego"];
const newNames = names.filter(name => {
return name.includes('a');
});
// Reduce()
// Takes an array and reduces it to a single value
// It differs in callback arguments
// The callback receives the accumulator (accumulates all returned values)
// It's value is the accumulation of the previous returned accumulations
const numbers = [1, 2, 3, 4, 5];
const final = numbers.reduce((acc, currValue, currIndex, array) => {
console.log(acc, currValue);
return acc + currValue;
},0) // this 0 here is optional. You are telling what value to start with