function avoidObstacles(nums) {
// write code here.
let hs= [];
let max = nums[0];
for (i=0; i<nums.length; i++) {
hs.push(nums[i]);
max = Math.max(max, nums[i]);
}
// checking for every possible length which
for (var i = 1; i <= max; i++) {
let j;
for (j = i; j <= max; j = j + i) {
// if there is obstacle, break the loop.
if (hs.includes(j))
break;
}
// If above loop did not break
if (j > max)
return i;
}
return max+1;
}
/**
* 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);
});
});