{
const a = [1, 3, 6, 4, 2, 1];
const b = [1, 2, 3];
const c = [-1, -3];
return [solution(a), solution(b), solution(c)];
function solution(arr) {
return Math.max(getSmallestPositive(arr.sort()), 1)
}
function solution1(arr) {
const sorted = arr.reduce((res, n, i) => {
for (let j = 0; j < res.length; j++) {
if (res[i] < res[j]) {
const x = res[j];
res[j] = res[i];
res[i] = x;
}
}
return res;
}, arr.slice());
return Math.max(getSmallestPositive(sorted), 1);
}
function getSmallestPositive(arr) {
const lastIdx = arr.length - 1;
for (let i = 1; i <= arr[lastIdx]; i++) {
if(!arr.includes(i)) {
return i;
}
}
return arr[lastIdx] + 1;
}
}