scrimba
Note at 2:42
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 2:42
AboutCommentsNotes
Note at 2:42
Expand for more info
main.js
run
preview
console
function arrayPreviousLess(nums) {
// write code here.

const results = [];

for (let i = 0; i < nums.length; i++){

const previousNum = nums[i - 1];
const currentNum = nums[i];

if(previousNum < currentNum){

results.push(previousNum)
} else {

results.push(-1)
}
}



return results


}



/**
* Test Suite
*/
describe('arrayPreviousLess()', () => {
it('shift previous postions from the left to a smaller value or store -1', () => {
// arrange
const nums = [3, 5, 2, 4, 5];

// act
const result = arrayPreviousLess(nums);

// log
console.log("result: ", result);

// assert
expect(result).toEqual([-1, 3, -1, 2, 4]);
});
});
Console
"dime"
,
undefined
,
"inside"
,
"dime"
,
undefined
,
"dime"
,
undefined
,
"inside"
,
"dime"
,
undefined
,
"dime"
,
undefined
,
"result: "
,
[
-1
,
3
,
-1
,
2
,
4
]
,
/index.html
LIVE