Skip to content

Instantly share code, notes, and snippets.

@Underdoge
Created March 3, 2017 23:26
Show Gist options
  • Save Underdoge/2842a8d920e549fe22f3621538230b13 to your computer and use it in GitHub Desktop.
Save Underdoge/2842a8d920e549fe22f3621538230b13 to your computer and use it in GitHub Desktop.
avoidObstacles
function avoidObstacles(inputArray) {
var min=2;
var test=false;
var max=inputArray.reduce(function(a, b) {
return Math.max(a, b);
});
while(min<=max+1&&!test){
test=true;
for(var i=0;i<inputArray.length&&test;i++){
console.log(inputArray[i]+" "+min);
if(inputArray[i]%min==0){
test=false;
}
}
min++;
}
min--;
return min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment