Open this example in the interactive library
Source code
const recent = (items, item, limit) =>
[item, ...items.filter((x) => x !== item)].slice(0, limit);
console.log(recent(["b", "a", "c"], "a", 3));
Sample output
[ 'a', 'b', 'c' ]

Create a bounded recent list. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
const recent = (items, item, limit) =>
[item, ...items.filter((x) => x !== item)].slice(0, limit);
console.log(recent(["b", "a", "c"], "a", 3));
[ 'a', 'b', 'c' ]