scrimba
Note at 0:02
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:02
AboutCommentsNotes
Note at 0:02
Expand for more info
main.js
run
preview
console
function avoidObstacles(nums) {
let arr = []
let maxValue = Math.floor(nums[nums.length-1] / 2)
let checker = (arr, target) => target.every(v => !arr.includes(v))
for (let x = 2; x < maxValue+1; x++ ) {
for(let y = 1; y < maxValue; y++) {
arr.push([x] * [y])
}
if(checker(arr,nums)) {
return arr[0]
}
arr = []
}
}



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