Created
October 15, 2020 12:52
-
-
Save Aldhanekaa/2b87d3180d2c0263235cab59a020b625 to your computer and use it in GitHub Desktop.
FCC course challenge
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
const squareList = (arr) => { | |
// Only change code below this line | |
if (Array.isArray(arr)) { // check if the arr is an arrat | |
console.log('hello world') | |
arr = arr.filter(element => typeof parseInt(element) == 'number') | |
.filter(element => element > 0 && element.toString().indexOf('.') == -1) | |
.map(element => element ** 2); | |
console.log(arr) | |
return arr; | |
}else | |
return 'OOPS arr is not an Array!' | |
// Only change code above this line | |
}; | |
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]); | |
console.log(squaredIntegers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Functional Programming: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem