Is it possible to return the result of the declared function?

  • 0
    reverseflat = function(array){
    if(array.length==1){return array[0]};
    const f=(arr,acc=[])=>arr.length>1?f(arr.slice(0,-1),acc.concat(arr.slice(-1)[0])):
    acc.concat(arr[0]);
    return f(array)}

    Is it possible during the declaration of f () to immediately pass a parameter of the parent function to it and return the result to get something like this:
    ..........................
    return f(array)=f(arr,acc=[])=>arr.length>1?f(arr.slice(0,-1),acc.concat(arr.slice(-1)[0])):
    acc.concat(arr[0]);}
    JavaScript Ethan Barry, Aug 16, 2020

  • 1 Answers
  • 0
    reverseflat = function(array){
    if(array.length==1){return array[0]};
    return ((arr,acc=[])=>arr.length>1?f(arr.slice(0,-1),acc.concat(arr.slice(-1)[0])):
    acc.concat(arr[0]))(array)}
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!