Advertisement
Guest User

Untitled

a guest
Mar 18th, 2022
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumOfTwoNumbers(input) {
  2.     let start = Number(input[0]);
  3.     let end = Number(input[1]);
  4.     let magic = Number(input[2]);
  5.     //let combination = 1;
  6.     let combination = 0;
  7.  
  8.     let flag = false;
  9.     for (let i = start; i <= end; i++) {
  10.         for (let j = start; j <= end; j++) {
  11.             combination++; // added
  12.             let sum = i + j;
  13.             if (sum === magic) {
  14.                 console.log(`Combination N:${combination} (${i} + ${j} = ${magic})`);
  15.                 flag = true;
  16.                 break;
  17.             }
  18.  
  19.  
  20.             //combination++;
  21.         }
  22.  
  23.         if (flag === true) {
  24.             break;
  25.         }
  26.     }
  27.  
  28.     if (flag === false) {
  29.        // console.log("No combination.");
  30.         console.log(`${combination} combinations - neither equals ${magic}`);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement