DEV Community

Discussion on: Welcome Thread - v51

Collapse
 
aelmosalamy profile image
Adham Elmosalamy

Hey there! @aelmosalamy here, I am an aspiring full-stack developer (hopefully I can say that I am, one day); Originally a Pythonista, and currently catching up with the web development train; I have been working lately on FreeCodeCamp so I can establish some knowledge in the full-stack, I was able to finish the 1st certificate and currently I've almost finished the 2nd certificate, I am planning to go all the way to the end, building some projects along the way, trying to establish an internet identity and struggling to publish tutorials and create educational content, which is something I have always wanted to do, but never had the will, So yeah, well, that's it. Peace.

Collapse
 
brandonmcconnell profile image
Brandon McConnell

Hey @aelmosalamy , I found your fibonacci one-liner solution on Reddit while building the exact same thing. Yours is great! I wanted to achieve this myself without recursion or default parameters, and this is what I came up with:

const fib = n => n > 3 ? [0,1,1,...Array(n-3).fill()].map((e,i,a) => a[i-2] ? ((a[i] = a[i-2] + a[i-1]) || a[i-2] + a[i-1]) : e) : [0,1,1].slice(0,n);

fib(0);  // []
fib(1);  // [0]
fib(3);  // [0, 1, 1]
fib(10); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Enter fullscreen mode Exit fullscreen mode

Essentially, hijacking the array clone set by the array.prototype.map() function. Thanks for the challenge! 🙌🏼

Collapse
 
aelmosalamy profile image
Adham Elmosalamy

Wow, I find it rather interesting how you found me here from reddit 😂
Anyways, brilliant solution, took me some time to understand, glad you liked it, keep it up!