Skip to content

Instantly share code, notes, and snippets.

@iqbalfasri
Last active November 30, 2019 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iqbalfasri/63cc60b2d50ab7204454368d9b30e57b to your computer and use it in GitHub Desktop.
Save iqbalfasri/63cc60b2d50ab7204454368d9b30e57b to your computer and use it in GitHub Desktop.
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