scrimba
Note at 1:18
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 1:18
AboutCommentsNotes
Note at 1:18
Expand for more info
main.js
run
preview
console
function avoidObstacles(nums) {
let jump = nums.sort((a, b) => a - b)[0] + 1;
let jumpSum = jump * 2;
const setJumpSize = () => {
if (nums.includes(jump) || nums.includes(jumpSum)) {
jump += 1;
jumpSum = jump * 2;
setJumpSize();
}
};
setJumpSize();

const testJumpSize = () => {
if (nums.includes(jumpSum)) setJumpSize();
jumpSum += jump;
if (nums.includes(jumpSum)) testJumpSize();
};

testJumpSize();
return jump;
}



/**
* 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