← Back to challenges

Odd Up, Even Down — N Times

JavaScriptHardarrayscontrol_flowloops

Instructions

Create a function that performs an even-odd transform to an array, n times. Each even-odd transformation:

  1. Adds two (+2) to each odd integer.
  2. Subtracts two (-2) from each even integer.

Examples

evenOddTransform([3, 4, 9], 3) ➞ [9, -2, 15]
// Since [3, 4, 9] => [5, 2, 11] => [7, 0, 13] => [9, -2, 15]

evenOddTransform([0, 0, 0], 10) ➞ [-20, -20, -20]

evenOddTransform([1, 2, 3], 1) ➞ [3, 0, 5]

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Chess Board Squares