Created
June 13, 2019 04:12
-
-
Save adyngom/f45e00018fdda33ef15dc31a5324413a to your computer and use it in GitHub Desktop.
Max difference in a set of numbers
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
const nums = [2, 4, 7, 5, 13, 11, 9, 1, 6, 2]; | |
console.log(getMaxDifference(nums)); | |
function getMaxDifference(arr) { | |
let max = arr[0], min = arr[0]; | |
[...arr].forEach(n => { | |
if(n > max) max = n; | |
if(n < min) min = n; | |
}); | |
return max - min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment