Understanding Recursive Functions

preview_player
Показать описание
Every so often, it's time to revisit past topics. Today, that topic is recursion!

My current situation doesn't lend well to recording videos, but I should be able to crank out some dev-related writing fairly often and still get some content out to anyone who is interested.

It's fully possible that the original explanation works better for you. If that's the case, all the power to you :)
Рекомендации по теме
Комментарии
Автор

Excellent explanation, thanks Nathan.

sweeball
Автор

I've just started learning JavaScript, this is helpful.

awdrifter
Автор

hay! U have assumption that arr is not empty. IMHO in your 1st prog need test arr.length==0 and exit if true before pattern assigment.

GOOD VIDEO by the way

qulinxao
Автор

I think my favourite algorithm in terms of recursive functions has to be quicksort.

const qsort = ([ hd, ...tl ]) =>
!hd ? []
: [...qsort(tl.filter(e => e < hd)), hd, ...qsort(tl.filter(e => e >= hd))];

qsort([6, 2, 9, 12, 34, 44, 75, 34, 42, 21, 7, 33, 27, 22, 56]);
// => [ 2, 6, 7, 9, 12, 21, 22, 27, 33, 34, 34, 42, 44, 56, 75 ]

It really does show off the power of recursion and, from a programmers' point of view, has a beautiful symmetry!

NB: After a moment of reflection I think I should clarify that the quick sort here was proffered to show off the use of recursion and what can be achieved with it. I do not suggest that this would be used instead of Array.prototype.sort in production code.

sweeball
visit shbcf.ru