Last active
November 30, 2019 18:20
-
-
Save iqbalfasri/63cc60b2d50ab7204454368d9b30e57b to your computer and use it in GitHub Desktop.
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 array = [4, 2, 1, 5]; | |
const maxDiff = array => { | |
let result = 0; | |
for(let i = 0; i < array.length; i++) { | |
for(let j = i+1; j < array.length; j++) { | |
if(array[i] < array[j] && i < j) { | |
result = array[j] - array[i] | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment