Skip to content

Instantly share code, notes, and snippets.

@alisonailea
Last active April 27, 2018 22:56
Show Gist options
  • Save alisonailea/6734457688d21e11971de9d571a0da8a to your computer and use it in GitHub Desktop.
Save alisonailea/6734457688d21e11971de9d571a0da8a to your computer and use it in GitHub Desktop.
CodeChallenge: Return a copy of the provided array with the the largest item removed.
// Return a copy of the provided array with the the largest item removed.
// I think this is the most performant way to do this.
const removeLargest = (items) => {
const newArray = [...items];
newArray.sort((a, b) => a-b)
newArray.pop();
return newArray;
}
const items = [5, 7, -11, 0, 33, 1, 5];
console.log(removeLargest(items));
console.log(items);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment