[자바스크립트/알고리즘] 양의 정수만 출력 (filter, map)
알고리즘/FreeCodeCamp 2021. 1. 16. 22:16

입력: positiveIntList([-3, 4.8, 5, 3, -3.2]); 출력: 5, 3 const positiveIntList = arr => { return arr.filter(num => num > 0 && num % parseInt(num) === 0) }; 결과값에 2승한 값을 출력하고 싶다면? const positiveIntList = arr => { return arr.filter(num => num > 0 && num % parseInt(num) === 0) .map(num => Math.pow(num,2)) }; map()을 추가해주면 된다. 문제 출처: www.freecodecamp.org