scrimba
Note at 0:57
Go Pro!

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:57
AboutCommentsNotes
Note at 0:57
Expand for more info
main.js
run
preview
console
function avoidObstacles(nums) {
// write code here.
nums.sort((a, b) => {
return a - b;
});
const lastArrVal = nums[nums.length - 1];
console.log(lastArrVal);

for(let i = 1; i <= lastArrVal + 1; i++){console.log(i)

if(nums.every((el)=>{
return 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);
});
});
Console
9
,
1
,
2
,
3
,
4
,
"result: "
,
4
,
/index.html
LIVE