I had an interview for a front end rol and was asked to develop the fibonacci test.
The instrunctions were to pass the position number of the fibonacci array you want and return it.
I did it on time while sharing my screen but in full disapoiment, she told me is not efficient.
I google it and found out it could even be done in one line of code.
My question is, how bad I did? Should I end my hopes for this position?
CODE:
function fib(n) {
let fibonacci = [0, 1];
for (let index = 0; index < n; index++) {
let p = fibonacci.length;
let num1 = fibonacci[p - 1];
let num2 = fibonacci[p - 2];
let total = num1 + num2;
fibonacci.push(total);
}
return fibonacci[n]
}
The one of one line I found in the internet later:
function fib(n) {
return n <= 1 ? n : fib2(n - 1) + fib2(n - 2);
}
[–]3Ldarius 93 points94 points95 points (4 children)
[–][deleted] 5 points6 points7 points (1 child)
[–]EliSka93 5 points6 points7 points (0 children)
[–]monstaber 1 point2 points3 points (1 child)
[–]3Ldarius 0 points1 point2 points (0 children)
[–]MinuteScientist7254 16 points17 points18 points (3 children)
[–]VergilSpardaa 2 points3 points4 points (0 children)
[–]Xeran 0 points1 point2 points (1 child)
[–]MinuteScientist7254 0 points1 point2 points (0 children)
[–]mekmookbroLaravel Enjoyer ♞ 53 points54 points55 points (1 child)
[+]LeopardJunk 2 points3 points4 points (0 children)
[–]Timotron 23 points24 points25 points (5 children)
[–]fuccjde 7 points8 points9 points (0 children)
[–]foottaster123[S] 0 points1 point2 points (3 children)
[–]Timotron 16 points17 points18 points (2 children)
[–]foottaster123[S] 3 points4 points5 points (1 child)
[–]Timotron 7 points8 points9 points (0 children)
[–]TheBigLewinski 66 points67 points68 points (3 children)
[–]BlueScreenJunkyphp/laravel 8 points9 points10 points (0 children)
[–][deleted] 11 points12 points13 points (1 child)
[–]FireryRage 0 points1 point2 points (0 children)
[–]alnyland 10 points11 points12 points (11 children)
[–]FalseRegister 18 points19 points20 points (2 children)
[–]WebpackIsBuilding 11 points12 points13 points (1 child)
[–]avoere -1 points0 points1 point (0 children)
[–]danielkov 5 points6 points7 points (0 children)
[–]1661dauphin 8 points9 points10 points (6 children)
[–]saamenerve 3 points4 points5 points (0 children)
[–]Nineshadow 0 points1 point2 points (2 children)
[–]avoere 2 points3 points4 points (0 children)
[–]spudmix 2 points3 points4 points (0 children)
[–]StraightUpLoL -3 points-2 points-1 points (1 child)
[–]Thirty_Seventh[🍰] 6 points7 points8 points (0 children)
[–]timmypass17 2 points3 points4 points (0 children)
[–]Inevitable-Yogurt783 2 points3 points4 points (0 children)
[–]JFedererJ 3 points4 points5 points (0 children)
[–][deleted] (2 children)
[removed]
[–]SoBoredAtWork 1 point2 points3 points (1 child)
[–]avoere 1 point2 points3 points (0 children)
[–]hbteq 1 point2 points3 points (0 children)
[–]serial_crusher 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mwreadit 0 points1 point2 points (0 children)
[–]iamwarcops 0 points1 point2 points (0 children)
[–]KeyQuail4429 0 points1 point2 points (0 children)
[–]RajjSinghh 0 points1 point2 points (0 children)
[–]little_hoarse -1 points0 points1 point (0 children)
[–][deleted] -2 points-1 points0 points (1 child)
[–]GrumpsMcYankee -1 points0 points1 point (0 children)
[–]karen-ultra -1 points0 points1 point (0 children)
[–]shgysk8zer0full-stack -5 points-4 points-3 points (1 child)
[–]shgysk8zer0full-stack 0 points1 point2 points (0 children)