Ad
Arrays
Data Types

Write a program that removes the element at the nth index in the provided array, and returns the new array.

If the number provided is not an index in the array, return the original array.

For Example:

remove([1, 2, 3], 2) => [1, 2]

remove(["dog", "cat", "bat", "parrot", "monkey"], 4) => ["dog", "cat", "bat", "parrot"]

function remove (arr, n) {
  if (n < 0 || n >= arr.length) return arr;
  arr.splice(n, 1);
  return arr;
}