function avoidObstacles(nums) {
// write code here.
nums.sort((a, b) => a - b);
//If they're all odd, then the answer is 2
if( nums.every(num => num %2 !== 0) ) {
return 2;
}
//If none of the obstacles are divisible by x, then the answer is x
let foundDivisor = false;
let count = 2;
while(!foundDivisor) {
if( nums.every(num => num %count !== 0) ) {
foundDivisor = true;
break;
return count;
}
}
}
/**
* Test Suite
*/
describe('avoidObstacles()', () => {
it('returns minimal number of jumps in between numbers', () => {
// arrange
const nums = [5, 3, 6, 7, 9];
// act
const result = avoidObstacles(nums);
// log
console.log("result: ", result);
// assert
expect(result).toBe(4);
});
});