Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumOfTwoNumbers(input) {
- let firstNum = Number(input[0]);
- let secondNum = Number(input[1]);
- let magicNum = Number(input[2]);
- let combinations = 0;
- for (let i = firstNum; i <= secondNum; i++) {
- for (let j = firstNum; j <= secondNum; j++) {
- combinations++;
- if (i + j === magicNum) {
- console.log(`Combination N:${combinations} (${i} + ${j} = ${magicNum})`);
- return;
- }
- }
- }
- console.log(`${combinations} combinations - neither equals ${magicNum}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement