← Back to challenges

Extending the Array Prototype

JavaScriptHardlanguage_fundamentalsarraysmath

Instructions

Write the following functions to extend the array prototype, by adding the methods:

  1. square()
  2. cube()
  3. divisible_by(x)
  4. strictly_above(x)
  5. strictly_below(x)

Examples

[1, 2, 3].square ➞ [1, 4, 9]

[1, 2, 3].cube ➞ [1, 8, 27]

[1, 2, 3, 4].divisible_by(2) ➞ [2, 4]

[1, 2, 3, 4].strictly_above(1) ➞ [2, 3, 4]

[1, 2, 3, 4].strictly_below(2) ➞ [1]

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.