← Back to Loops
Question 35
map + filter: Square Even Numbers
map + filter: Square Even Numbers
Use filter first to keep even numbers, then use map to square them. Print the result as comma-separated values.
Array:
[1, 2, 3, 4, 5, 6, 7, 8]
Steps:
1. Create an evens variable by filtering the array to keep only even numbers
2. Create a squared variable by mapping evens to num * num
3. Print squared with join(',')Expected Output:
4,16,36,64= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
LoopsArraysmapfilter
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (clog, fn, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.