This Gist was automatically created by Carbide, a free online programming environment.
Last active
September 21, 2016 21:28
-
-
Save peterschussheim/aa0728bb4392e76dfaaade8ccdd1c1fd to your computer and use it in GitHub Desktop.
removeSmallest
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
// removeSmallest :: [Number] -> [Number] ///- remove min from array numbers//- if there are duplicates of a particular element, remove the one with the LOWER index//- if numbers.length = 0, return [] | |
function removeSmallest(numbers) { | |
if (numbers.length === 0) { | |
return []; | |
} | |
return numbers.reduce(function(prev, curr) { | |
return Math.min(prev, curr); | |
}); | |
} | |
var num1 = [5, 3, 2, 1, 4]; | |
var num2 = [5, 3, 1, 1, 4, 2]; | |
var minNum1 = removeSmallest(num1); | |
var minNum2 = removeSmallest(num2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment