6 kyu

HyperReduce

Description:

Hi, it's Vaults. Welcome to my second kata!   
\(^O^)/

Background info


To be able to complete the kata, you will need to be able to comprehend these two resources:

Definition


With that in the back of our minds, let's make a wholly insane function! The idea is that our function returns a reduce function that is agnostic to the amount of function calls, arguments and array nests in between. What?! Let's look at some examples to clarify:

const adder = (accumulator, next) => accumulator + next;
const add = hyperReduce(adder, 0);

add has become a function that would have the following inputs and outputs

  • add(3) //=> 3
  • add(3, 3, 3) //=> 9
  • add(3, 3, 3)(3) //=> 12
  • add(3, 3, 3)([3,3]) //=> 15
  • add(3, 3, 3)([3,[3]]) //=> 15
  • add([[[[[[[[[[3]]]]]]]]]])() => 3

Misc


You are also expected to be able to handle multiplication, division, concatenation and composition. Couldn't think of a legitimate use case except for code challenges. Enjoy implementing this :) If there's anything I left vague, look at the test cases. Anything else was unintentional so please let me know.

Fundamentals

More By Author:

Check out these other kata created by Vaults

Stats:

CreatedMar 27, 2018
PublishedMar 27, 2018
Warriors Trained370
Total Skips32
Total Code Submissions535
Total Times Completed41
JavaScript Completions41
Total Stars22
% of votes with a positive feedback rating100% of 14
Total "Very Satisfied" Votes14
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Vaults Avatar
  • jhoffner Avatar
Ad