Skip to content

Instantly share code, notes, and snippets.

@Joejhorn
Created February 19, 2018 21:17
Show Gist options
  • Select an option

  • Save Joejhorn/ecbcebf06c2b06c4f9ae5782fb38e781 to your computer and use it in GitHub Desktop.

Select an option

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
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