Consider:
c=(a,b)=>(+a||0)+(+b||0)
Yes, it is not good to solve it like that. But I want to shorten it even more. If a is a string and b is a string, then return 0. If one is a number, return it (floats and intergers). And if both inputs are numbers, then return the sum (if either string can be cast to a number, treat it as a number).
I tried to shorten this more, but I just can’t.
This is the specification for the task:
Usage
node app.js
Expected behavior
The program returns the sum of two numbers. If no numbers are provided, the result should be 0. If only one number is provided, only that number should be returned.
Tests
node app.js 4 5 # 9
node app.js 4 # 4
node app.js 4 a # 4
node app.js a 4 # 4
node app.js a b # 0
node app.js 2.1 b # 2.1
node app.js 2.1 2.5 # 4.6
node app.js # 0
Update
It also needs to handle floats as well not only integers.
This is my current code (only the code on line 1 should be optimized to be as small as possible):
c=(a,b)=>(+a||0)+(+b||0)
const input1 = process.argv[2];
const input2 = process.argv[3];
const result = c(input1, input2);
console.log(result);
aandbare both strings, but ones which cast into numbers? Your code treats them as numbers, but the description seems to imply we need to actually check if they're strings \$\endgroup\$(a,b)=>toa=>b=>for -1 byte. ;) \$\endgroup\$