function solution(n,arr) {
let answer = '';
let cash = Array.from({length: n}, ()=>0)
for(let a of arr) {
if(cash.indexOf(a) < 0) {
cash.unshift(a);
cash.pop();
} else {
cash.splice(cash.indexOf(a),1);
cash.unshift(a);
}
}
answer = cash;
return answer;
}
console.log(solution(5, [1,2,3,2,6,2,3,5,7]))