let res = []
for(let i = 0; i < nums.length; i++){
let found = false
for(let j = i - 1; j >= 0; j--){
if(nums[j]<nums[i]){
res.push(nums[j])
found = true
console.log(nums[i], nums[j])
break
}
}
if(!found){
res.push(-1)
}
}
return res
}
/**
* 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]);
});
});
function arrayPreviousLess(nums) {
// write code here.