Today, I am reviewing JavaScript. I grasp the concepts, but I find myself struggling to piece everything together independently. Today’s focus was on the array methods: .map, .filter, and .reduce.
1. .map()
Purpose: Transforms each element in an array and creates a new array.
Use case: When you want to apply a function to every element in an array.
Syntax:
const newArray = array.map(callback);
Example:
const numbers = [1, 2, 3, 4];
const doubled = numbers.map(num => num * 2);
console.log(doubled); // Output: [2, 4, 6, 8]
2. .filter()
Purpose: Filters elements in an array based on a condition and returns a new array.
Use case: When you want to keep only the elements that satisfy a specific condition.
Syntax:
const newArray = array.filter(callback);
Example:
const numbers = [1, 2, 3, 4];
const evens = numbers.filter(num => num % 2 === 0);
console.log(evens); // Output: [2, 4]
3. .reduce()
Purpose: Reduces an array to a single value by applying a function to an accumulator and each element.
Use case: When you want to calculate a single value, like a sum or a product.
Syntax:
const result = array.reduce((accumulator, currentValue) => {
// Logic
return updatedAccumulator;
}, initialValue);
Example:
const numbers = [1, 2, 3, 4];
const sum = numbers.reduce((acc, num) => acc + num, 0);
console.log(sum); // Output: 10
I have several assignments to work on that involve these methods and objects.
Alex received a jury duty summons, and Kel believes that the lack of transportation an hour away could be a valid excuse. Tommy, however, disagrees. Alex may need to check in for jury duty, which I believe can be done over the phone. Additionally, there is a bus service available, so the claim of no transportation isn’t entirely accurate.
I don’t have much to discuss today. I’m managing fairly well mentally, though I still experience some anxiety due to the state of the world. To alleviate my anxiety, I try to stay away from the news. While I don’t want to be uninformed, I also prefer not to exist in a constant state of panic.
Alex has asked me to place some papers into the safe, but I must admit that I need to sort through it first, as it’s becoming quite full, and “some papers” don’t really fit.
Someone left the front door open, so I had to take a can of cat food and flick the lid to coax the cats back inside. Fortunately, Sandy and O’Malley didn’t wander far and returned quickly. Karissa is now feeding all the cats since they’re hungry and it’s close to dinner time. Emily was the only cat that didn’t go outside, although she isn’t really one to venture outdoors.





