Fibonacci sequence and nth number with reduce() const generateFibonnaciSequence = (n) =&gt; {
    return [
        (arr = new Array(n).fill(1).reduce((arr, _, i) =&gt; {
            arr.push(i &lt;= 1 ? 1 : arr[i - 2] + arr[i - 1]);
            return arr;
        }, [])),
        arr[n - 1],
    ];
};

const [fibonacciSequence, fibonacciNthNumber] = generateFibonnaciSequence(n);

My idea is to return an array holding fibonacci sequence up to n in index 0 and fibonnaci's n-th value in index 1. Can someone help me with a prettier way of constructing this function. I'd like to avoid holding the array in temp arr variable if possible, but still use a single expression for return statement.
A short review;

I prefer fat arrow syntax =&gt; for inline functions
Its a good exercise to code this with reduce but it is definitely not the best option for production code. (That would be a non-recursive old skool loop)
The modern approach to Fibonacci numbers has them start with [0,1,1] not [1,1]
If you have control over what the function returns, then I would just return the sequence. It is trivial for the caller to get the last value in the array

Please find below a counter proposal, I like that it support both the old and new style sequence.


function buildFibonnaciSequence(n){
  const start = [0,1];
  //Recursion exit lane
  if(n &lt;= 1){
    return [start.slice(0,n+1), start[n]];
  }
  //Recurse
  const priorSequence = buildFibonnaciSequence(n-1);
  //Build return value
  const nValue = priorSequence[0][n-2] + priorSequence[0][n-1];
  return [[...priorSequence[0], nValue], nValue];
}

console.log(buildFibonnaciSequence(0));
console.log(buildFibonnaciSequence(1));
console.log(buildFibonnaciSequence(5));
console.log(buildFibonnaciSequence(45));