728x90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filter Range | |
// Write a function filterRange(arr, a, b) that gets an array arr, | |
// looks for elements with values higher or equal to a and lower or equal to b and return a result as an array. | |
// !! The function should not modify the array. It should return the new array. | |
function filterRange(arr, a, b) { | |
return arr.filter(arr => (arr >= a && arr <= b)); | |
} | |
const arr = [5, 3, 8, 1]; | |
const filtered = filterRange(arr, 1, 4); | |
console.log( filtered ); // 3,1 (matching values) | |
console.log( arr ); // 5,3,8,1 (not modified) |
'Algorithm > JavaScript(Node.js)' 카테고리의 다른 글
The Modern JS Tutorial: array-methods: calculator (0) | 2021.09.20 |
---|---|
The Modern JS Tutorial: array-methods: filterRangeInPlace (0) | 2021.09.13 |
The Modern JS Tutorial: array-methods: camelize (0) | 2021.09.13 |
백준 15652번: N과 M (4) Node.js(JavaScript) (0) | 2020.02.27 |
백준 15651번: N과 M (3) Node.js(JavaScript) (0) | 2020.02.25 |