const arrayPreviousLess = (nums) =>
nums.map(
(num, i, arr) =>
arr
.slice(0, i)
.reverse()
.find((el) => el < num) || -1
);
/**
* Test Suite
*/
describe('arrayPreviousLess()', () => {
it("shift previous postions from the left to a smaller value or store -1", () => {
// arrange
const nums = [9, 5, 2, 8, 11, 1, 6];
// act
const result = arrayPreviousLess(nums);
// log
console.log("result: ", result);
// assert
expect(result).toEqual([-1, -1, -1, 2, 8, -1, 1]);
});
it("shift previous postions from the left to a smaller value or store -1", () => {
// arrange
const nums = [3, 5, 2, 4, 5, 3];
// act
const result = arrayPreviousLess(nums);
// log
console.log("result: ", result);
// assert
expect(result).toEqual([-1, 3, -1, 2, 4, 2]);
});
});