Question: I have a function like that:

```
function intiFun(initValue) {

    const firstResult = firstFun(initValue);
    const secondResult = secondFun(firstResult);
    const thirdResult = thirddFun(secondResult);
    const fourthResult = fourthFun(thirdResult);
    return fourthResult;
}

```

but i want to write it better. and i dont want to save value from each function as variable.

is there any solution to to call functions with out save old value

like rxjs or somthing like that: 

```
function intiFun(initValue) {
    return firstFun(initValue).secondFun().thirddFun().fourthFun();
}

```

or more better like that:

```
function intiFun(initValue) {
    return firstFun(initValue)         
          .secondFun(secondInput)
          .thirddFun(secondInput)
          .fourthFun(secondInput)
}

function secondFun(value, secondInput) {
    return ...;
}
...

```

or some liberally to do that (maybe lodash)

Answer: 
```
const firstFun  = x => { /* return ... */ };
const secondFun = x => { /* return ... */ };
const thirdFun  = x => { /* return ... */ };
const fourthFun = x => { /* return ... */ };

const callAll= (value, ...functions) => {
   functions.forEach(fn => value = fn(value));
   retrun value;
}

const result = callAll(3, firstFun, secondFun, thirdFun, fourthFun);

console.log(result);

```
```
function initFun(initValue) {
    return fourthFun(thirddFun(secondFun(firstFun(initValue))));
}

```

Alternatively, convert your function into promises:

```
function initFun(initValue) {
    return firstFun(initValue)
        .then(secondFun)
        .then(thirddFun)
        .then(fourthFun);
}

```