Last active
April 27, 2018 22:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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