Skip to content

Instantly share code, notes, and snippets.

@acalpixca
Last active February 19, 2018 14:44
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 acalpixca/6640853746c91920be384b913f48ffb4 to your computer and use it in GitHub Desktop.
Save acalpixca/6640853746c91920be384b913f48ffb4 to your computer and use it in GitHub Desktop.
cassidoo challenge 18/02/2018
function minimumDiff(p) {
// old school solution
diff=0;
if (p.length>1) {
diff=Math.abs(p[1]-p[0]);
for (i=0;i<p.length;i++){
for (j=i+1;j<p.length;j++){
if (Math.abs(p[j]-p[i])<diff){
diff=Math.abs(p[j]-p[i]);
}
}
}
}
return(diff);
}
console.log(minimumDiff([130,5,20,9]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment