Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumTwoNumbers(input) {
- let combinations = 0;
- let combinationFound = false;
- for (let i = 0; i < input.length; i++) {
- input[i] = Number(input[i]);
- }
- for (let i = (input[0]); i <= input[1]; i++) {
- for (let j = input[0]; j <= Number(input[1]); j++) {
- combinations++;
- if (i + j == input[2]) {
- console.log(`Combination N:${combinations} (${i} + ${j} = ${input[2]})`);
- combinationFound = true;
- break;
- }
- }
- if (combinationFound) {
- break;
- }
- if (!combinationFound) {
- console.log (`${combinations} - neither equals ${input[2]}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement