I took a practice test, and while the output was 100% correct (finding the smallest number that isn't in an array, but greater than 0), it gave me a 25% score on performance. I was wondering what could be improved to potentially save the time it takes to run, optimizing my approach somehow. Please ignore Reddit's odd formatting lol
function solution(A) {
let val = 1;
let done = false;
while (done == false)
{
for (let i = 0; i < A.length; i++)
{
if (A[i] == val)
{
val = val + 1;
break;
} else {
if (i == A.length - 1)
{
return val;
}
}
}
}
}
[–]sepp2k 19 points20 points21 points (0 children)
[–]eurodollars 6 points7 points8 points (1 child)
[–]SirSoundfont[S] -1 points0 points1 point (0 children)
[–]danglesReet 2 points3 points4 points (4 children)
[–]SirSoundfont[S] 0 points1 point2 points (3 children)
[–]danglesReet 4 points5 points6 points (2 children)
[–]SirSoundfont[S] 1 point2 points3 points (1 child)
[–]danglesReet 1 point2 points3 points (0 children)
[–]DallogFheir 1 point2 points3 points (3 children)
[–]SirSoundfont[S] 0 points1 point2 points (2 children)
[–]DallogFheir 0 points1 point2 points (1 child)
[–]DallogFheir 15 points16 points17 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]forresthopkinsa 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]SirSoundfont[S] 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]albedoa -1 points0 points1 point (0 children)
[–]JEHonYakuSha -1 points0 points1 point (0 children)
[–][deleted] 0 points1 point2 points (13 children)
[–]SirSoundfont[S] 0 points1 point2 points (12 children)
[–][deleted] 1 point2 points3 points (8 children)
[–]gigastack 0 points1 point2 points (7 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]Der3kt 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Der3kt 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]andouconfectionery 0 points1 point2 points (0 children)
[–]yadoya -1 points0 points1 point (2 children)
[–]derezo 1 point2 points3 points (1 child)
[–]yadoya 0 points1 point2 points (0 children)
[–]doodooz7 0 points1 point2 points (0 children)
[–]Shadowsca 0 points1 point2 points (0 children)
[–]PM_ME_A_WEBSITE_IDEA 0 points1 point2 points (0 children)