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