Issue
How can I create a one line function in typescript return like this:
sum(x)(y) -> x+y, e.g sums(2)(4) -> 6
Given that:
const result = sum(2)(4); // 6
console.log('Result:', result);
I have tried with a way like this:
function sum(x: number, y: number) {
return x + y;
}
Solution
Like this
const sum = (x: number, y: number): number => x + y;
console.log("sum", sum(1,2))
const sumNested = (x: number) => (y: number): number => x + y;
console.log("sumNested", sumNested(3)(4))
Answered By - Irfanullah Jan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.