ProdanTenev

Sum Of Two Numbers

Mar 2nd, 2022
1,033
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.69 KB | None | 0 0
  1. function sumoftwonums(input) {
  2.     let start = Number(input[0]);
  3.     let end = Number(input[1]);
  4.     let magicNumber = Number(input[2]);
  5.     let combinations = 0;
  6.     let isFound = false;
  7.     for (let x = start; x <= end; x++) {
  8.         for (let y = start ; y <= end; y++) {
  9.             combinations++;
  10.             if (x + y == magicNumber) {
  11.                 isFound = true;
  12.                 console.log(`Combination N:${combinations} (${x} + ${y} = ${magicNumber})`);
  13.                 break;
  14.             }
  15.         }
  16.         if (isFound) {
  17.             break;
  18.         }
  19.     }
  20.     if (!isFound){
  21.         console.log(`${combinations} combinations - neither equals ${magicNumber}`);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment