JS関数式プログラミング例(高次関数応用)
JS関数式プログラミング例
//JavaScript , ====>>>
//1.filter , , boolean
const nums = [10, 20, 30, 40, 50, 60];
//let numbers = nums.filter(n=>n>20);
//console.log(numbers);
//2.map
//let numbers = nums.map(item => item * 2);
//console.log(numbers);
//3.reduce
//let numbers = nums.reduce(((previousValue, currentValue) => previousValue + currentValue),1);
//console.log(numbers);
let numbers = nums.filter(item => item > 50).map(item => item * 2).reduce((previousValue, currentValue) => previousValue + currentValue);
console.log(numbers);