function arrayPreviousLess(nums) {
// write code here.
//Initialize the array, the first value will always be -1
const returnArray = [-1];
//loop through the array, starting on the 2nd value
for( i = 1; i < nums.length; i++ ){
if (nums[i] > nums[i-1]){
returnArray.push(nums[i-1]);
}else{
returnArray.push(-1);
}
}
return returnArray;
}
/**
* 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]);
});
});