Transformation Methods
Transformation Methods
Section titled “ Transformation Methods”Creates a new array by transforming each element.
const nums = [1, 2, 3];const doubled = nums.map(n => n * 2);// [2, 4, 6]Time: O(n) Mutates original? No
filter()
Section titled “filter()”Returns elements that match a condition.
const nums = [1, 2, 3, 4];const evens = nums.filter(n => n % 2 === 0);// [2, 4]Time: O(n) Mutates original? No
reduce()
Section titled “reduce()”Reduces array to a single value.
const nums = [1, 2, 3, 4];const sum = nums.reduce((acc, n) => acc + n, 0);// 10Time: O(n) Mutates original? No