Advertisement
Liliana797979

sum two numbers

Feb 17th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sumTwoNumbers(input) {
  2.     let combinations = 0;
  3.     let combinationFound = false;
  4.  
  5.     for (let i = 0; i < input.length; i++) {
  6.         input[i] = Number(input[i]);
  7.     }
  8.  
  9.     for (let i = (input[0]); i <= input[1]; i++) {
  10.         for (let j = input[0]; j <= Number(input[1]); j++) {
  11.             combinations++;
  12.             if (i + j == input[2]) {
  13.                 console.log(`Combination N:${combinations} (${i} + ${j} = ${input[2]})`);
  14.                 combinationFound = true;
  15.                 break;
  16.             }
  17.         }
  18.         if (combinationFound) {
  19.             break;
  20.         }
  21.         if (!combinationFound) {
  22.             console.log (`${combinations} - neither equals ${input[2]}`);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement