// function avoidObstacles(nums) {
// let maxNum = Math.max(...nums)
// console.log(maxNum)
// let jumpSize = 0
// let minJump
// while (!minJump) {
// jumpSize++
// currentJump = 0
// console.log(jumpSize)
// while (currentJump < maxNum) {
// console.log(currentJump)
// currentJump += jumpSize
// if (nums.includes(currentJump)) {
// break
// }
// if (currentJump > maxNum) {
// minJump = jumpSize
// }
// }
// }
// return minJump
// }
function avoidObstacles(nums) {
for (i = 1; i <= Math.max(...nums) + 1; i++) {
if(nums.every(el => el % i !== 0)) return i
}
}
/**
* 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);
});
});