DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Complete the function without using loops and conditions

// Complete the function
function calculate(n) {
    ...
};

calculate(48); // 52
calculate(52); // 48
Enter fullscreen mode Exit fullscreen mode

The function accepts one argument.
If 48 is passed then it should return 52,
& if 52 is passed then it should return 48

Write the function body without using loops (for, while..) or conditionals(if..else, ?:, switch)


Thanks for reading πŸ’™

Follow @codedrops.tech for daily posts.

Instagram ● Twitter ● Facebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Top comments (2)

Collapse
 
alekseiberezkin profile image
Aleksei Berezkin

You need just to...

Solution
Solve the system of 2 linear equations:
48a + b = 52
52a + b = 48

And the solution is: a = -1, b = 100. So,

function calculate(n) {
    return -n + 100
}

Collapse
 
ml318097 profile image
Mehul Lakhanpal

Awesome πŸ”₯πŸ‘