문제
Map, Filter, Reduce - Code Exercises | CroCoder
Map, filter and reduce are the most useful array methods to manipulate arrays and often the hardest to master. Try to solve the given exercises!
www.crocoder.dev
메모
// Arrow function
map((element) => { /* … */ })
map((element, index) => { /* … */ })
map((element, index, array) => { /* … */ })
// Callback function
map(callbackFn)
map(callbackFn, thisArg)
// Inline callback function
map(function (element) { /* … */ })
map(function (element, index) { /* … */ })
map(function (element, index, array) { /* … */ })
map(function (element, index, array) { /* … */ }, thisArg)
정답
const input = 6;
const arr = [];
for (let i = 1; i <= input; i++) {
arr.push(i);
}
console.log(arr.reduce((a, b) => a * b));
let input = 6;
let arr = Array(input)
.fill(1)
.map((a, b) => a + b)
.reduce((a, b) => a * b);
console.log(arr);