Created
February 19, 2018 21:17
-
-
Save Joejhorn/ecbcebf06c2b06c4f9ae5782fb38e781 to your computer and use it in GitHub Desktop.
filter() and map() freecodecamp - get rid of negative and doubles and then square them
This file contains hidden or 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 realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34]; | |
| const squareList = (arr) => { | |
| "use strict"; | |
| // change code below this line | |
| const squaredIntegers = | |
| arr.filter((number) =>{ | |
| if (number % 1 === 0 && number > 0){ | |
| return number; | |
| } | |
| }).map(number => number * number); | |
| // change code above this line | |
| return squaredIntegers; | |
| }; | |
| // test your code | |
| const squaredIntegers = squareList(realNumberArray); | |
| console.log(squaredIntegers); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment