Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumOfTwoNumbers(input) {
- let startNum = Number(input[0]);
- let endNum = Number(input[1]);
- let sum = Number(input[2]);
- let isFound = false;
- let combination = 0;
- let numberOne = 0;
- let numberTwo = 0;
- for (let first = startNum; first <= endNum; first++) {
- for (let second = startNum; second <= endNum; second++) {
- combination++;
- if (first + second === sum) {
- numberOne = first;
- numberTwo = second;
- isFound = true;
- break;
- }
- }
- if (isFound) {
- break;
- }
- }
- if (isFound) {
- console.log(`Combination N:${combination} (${numberOne} + ${numberTwo} = ${sum})`);
- } else {
- console.log(`${combination} combinations - neither equals ${sum}`);
- }
- }
- sumOfTwoNumbers(["1", "10", "5"])
Advertisement
Add Comment
Please, Sign In to add comment