Question: I have been mostly programming in Python. And this year, I learned how to do recursion using it. 

A really good technique my prof taught me is to use list comprehensions like so:

```
def list_all(obj):  

    if not isinstance(obj, list):  
        return [obj]  
    else:  
        return sum([list_all(x) for x in obj], []) 

```

Now that I am using JS more and more instead of Python, I am wondering what are specific built-in functions you can use in the language to help with recursion. I know that list comprehension are deprecated in JavaScript, so obviously I can't use them anymore. Would map or filter be good substitutes for list comprehensions in tackling recursion? If not, then what?

Answer: 
[Array comprehensions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions#Differences_to_the_older_JS1.7.2FJS1.8_comprehensions) were proposed and implemented by Mozilla as a part of their "Javascript 1.7" initiative (support of then-upcoming and later abandoned ES4) back in 2007, unfortunately they didn't make their way to the current standard (surely, something like `Object.getOwnPropertySymbolsOrSomeOtherUnreadableMess()` is much more important in terms of redability and efficiency). So, in JS you have to resort to `.map` for this kind of stuff:

```
let list_all = obj => {
   if (!Array.isArray(obj))
        return [obj];
    else
        return [].concat(...obj.map(list_all))
}

```
In JavaScript you can indeed use Array prototype methods like `.map()`, `.reduce()`, `.some()`, `.every()`, `.filter()`, to get things done, also recursive calls on arrays. In ES6 the spread syntax (much like the `*` in Python) allows to turn arrays into function arguments. In JavaScript arrays are concatenated with the `.concat()` method instead of Python's `+`, and the ternary operator is used more often than the `... if ... else ...` operator in Python.

Here is the ES6 code that does what your example Python script does:

```js
function flattenArray(obj) {
    return Array.isArray(obj) 
        ? [].concat(...obj.map(flattenArray)) 
        : [obj];
}
// Sample call:
var res = flattenArray([1,[2,3],[4,[5,6],7],8]);

console.log(res);
```