Extending the Array Prototype

Published by xAlien95 in

Extend the array structure by adding the following computed properties and methods:

  1. squared
  2. cubed
  3. divisible(by: x)
  4. strictly(above: x)
  5. strictly(below: x)

Examples

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

[1, 2, 3].cubed ➞ [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

Watch a quick demo on how Edabit works.