79151386

Date: 2024-11-02 18:50:22
Score: 2
Natty:
Report link

Check this video https://www.youtube.com/watch?v=xw5SJZnTWp4&t=224s

i noticed while trying this code which can help make a function to support currying, notice line 6 where return have (), without parentheses this code does not have capability to return a executable curried function

const addUncurried = (a, b) => a + b;
const curry = 
    (targetFunction, collectedArguments = []) => {
          return (...currentArguments) => {
              return (allArguments => {
                return (
                    allArguments.length >= targetFunction.length 
                    ? targetFunction(...allArguments) 
                    : curry(targetFunction, allArguments)
                )
              })([
                ...collectedArguments,
                ...currentArguments,
            ])
          }
    }
        
   
const addCurried = curry(addUncurried);
const increment = addCurried(2); // 6
console.log('increment',increment(4));
console.log('addCurried',addCurried(1,4)); // 5 
console.log('addCurried',addCurried(1)(3)); // 4

Reasons:
  • Blacklisted phrase (1): youtube.com
  • Blacklisted phrase (1): Check this video
  • Blacklisted phrase (1): this video
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Vinay Rajput