Invert an Array

Published by Mubashir Hassan in

Create a function that takes an array of numbers arr and returns an inverted array.

Examples

invert_array([1, 2, 3, 4, 5]) ➞ [-1, -2, -3, -4, -5]

invert_array([1, -2, 3, -4, 5]) ➞ [-1, 2, -3, 4, -5]

invert_array([]) ➞ []

Notes

  • Don't forget to return the result.
  • If you get stuck on a challenge, find help in the Resources tab.
  • If you're really stuck, unlock solutions in the Solutions tab.
Watch a quick demo on how Edabit works.