Advertisement
Spocoman

04. Sum of Two Numbers

Dec 30th, 2021 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumOfTwoNumbers(input) {
  2.     let firstNum = Number(input[0]);
  3.     let secondNum = Number(input[1]);
  4.     let magicNum = Number(input[2]);
  5.     let combinations = 0;
  6.  
  7.     for (let i = firstNum; i <= secondNum; i++) {
  8.         for (let j = firstNum; j <= secondNum; j++) {
  9.             combinations++;
  10.             if (i + j === magicNum) {
  11.                 console.log(`Combination N:${combinations} (${i} + ${j} = ${magicNum})`);
  12.                 return;
  13.             }
  14.         }
  15.     }
  16.    
  17.     console.log(`${combinations} combinations - neither equals ${magicNum}`);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement