Question: I try to get all files like scheme\_12.sql and scheme\_23\_analytics.sql from folder with bash and regex works in a strange way in terminal, doesn't return anything. Also checked in python re and some interactive regex sites. It works.

my command `ls | find . -type f -regex "\.\/scheme_[0-9]+_([a-zA-Z]+)?.sql"`

but command without optional sentence works `ls | find . -type f -regex "\.\/scheme_[0-9]+.sql"`

I have no idea why. Can you help me find a mistake?

Answer: 
Because `result` is being reinitialized to `[]` every time the function is called. You are not passing itself the previous `result`, so it gets reset. In the end, only the last iteration with the last index (`[5]`) is sent back.

What you can do is use a third argument, optional, that you can initialize to `[]`.

```js
function recursive(index,length, result=[]) {
  result.push(index);
  return (index < length) ? recursive(++index,length, result) : result;
}

console.log(recursive(1,5)); // [1,2,3,4,5]
```
One workaround could be to add an accumulator to your recursive function, in order to bring in every steps the array you started at the beginning of the first call.

```js
function recursive(index, length) {
  const result = [];
  result.push(index);
  return recursiveAcc(++index, length, result);
}

function recursiveAcc(index, length, result) {
  result.push(index);
  return (index < length) ? recursiveAcc(++index, length, result) : result;
}

console.log(recursive(1, 5)); // [ 1, 2, 3, 4, 5 ]
```