All Questions

552
votes
16answers
308717 views

Access / process (nested) objects, arrays or JSON

I have a (nested) data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)? For example: var data = { code: 42, it...
435
votes
14answers
87788 views

What is the most efficient/elegant way to parse a flat table into a tree?

Assume you have a flat table that stores an ordered tree hierarchy: Id Name ParentId Order 1 'Node 1' 0 10 2 'Node 1.1' 1 10 3 'Node 2' 0...
1160
votes
21answers
289453 views

What is tail recursion?

Whilst starting to learn lisp, I've come across the term tail-recursive. What does it mean exactly?
192
votes
20answers
64484 views

Understanding recursion

I'm having major trouble understanding recursion at school. Whenever the professor is talking about it, I seem to get it but as soon as I try it on my own it completely blows my brains. I was trying...
189
votes
11answers
190734 views

What is the maximum recursion depth in Python, and how to increase it?

I have this tail recursive function here: def fib(n, sum): if n < 1: return sum else: return fib(n-1, sum+n) c = 998 print(fib(c, 0)) It works up to n=997, then it just ...
256
votes
18answers
85804 views

Way to go from recursion to iteration

I've used recursion quite a lot on my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems. So, sometime in the very ...
516
votes
7answers
92878 views

What Is Tail Call Optimization?

Very simply, what is tail-call optimization? More specifically, Can anyone show some small code snippets where it could be applied, and where not, with an explanation of why?
131
votes
14answers
251431 views

How to search by key=>value in a multidimensional array in PHP

Is there any fast way to get all subarrays where a key value pair was found in a multidimensional array? I can't say how deep the array will be. Simple example array: $arr = array(0 => array(id=&...
162
votes
18answers
205541 views

Recursively list files in Java

How do I recursively list all files under a directory in Java? Does the framework provide any utility? I saw a lot of hacky implementations. But none from the framework or nio
164
votes
9answers
57090 views

Recursion in Angular directives

There are a couple of popular recursive angular directive Q&A's out there, which all come down to one of the following solutions: manually incrementally 'compile' HTML based on runtime scope sta...

Previous Next