map + filter: Square Even Numbers
easyQuestion 35Use 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, so 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.