scrimba
Note at 0:34
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:34
AboutCommentsNotes
Note at 0:34
Expand for more info
main.js
run
preview
console
function avoidObstacles(nums) {
// This assumes the lowest number in nums > 0 and there will be
// at least two numbers in the nums array.
let i = 2
const largestLength = Math.max(...nums) + 1
while (i < largestLength) {
if (!(nums.every(num => num % i))) { i++ } else { break }
}
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);
});
});
Console
"result: "
,
4
,
/index.html
LIVE