Last active
February 19, 2018 14:44
-
-
Save acalpixca/6640853746c91920be384b913f48ffb4 to your computer and use it in GitHub Desktop.
cassidoo challenge 18/02/2018
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
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