loading...

Complete the function without using loops and conditions

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read
// Complete the function
function calculate(n) {
    ...
};

calculate(48); // 52
calculate(52); // 48

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.

InstagramTwitterFacebook

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

codedrops.tech

Discussion

pic
Editor guide
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
318097 profile image
Mehul Lakhanpal Author

Awesome 🔥👍