Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sumOfTwoNumbers(input) {
- let firstNum = Number(input[0]);
- let secondNum = Number(input[1]);
- let magicNum = Number(input[2]);
- let combinations = 0;
- let isFound = false;
- for (let i = firstNum; i <= secondNum; i++) {
- for (let j = firstNum; j <= secondNum; j++) {
- combinations++;
- if (i + j === magicNum) {
- console.log(`Combination N:${combinations} (${i} + ${j} = ${magicNum})`);
- isFound = true;
- break;
- }
- }
- if (isFound) {
- break;
- }
- }
- if (isFound === false) {
- console.log(`${combinations} combinations - neither equals ${magicNum}`);
- }
- }
- РЕШЕНИЕ С PROCESS.EXIT(0):
- function sumOfTwoNumbers(input) {
- let firstNum = Number(input[0]);
- let secondNum = Number(input[1]);
- let magicNum = Number(input[2]);
- let combinations = 0;
- for (let i = firstNum; i <= secondNum; i++) {
- for (let j = firstNum; j <= secondNum; j++) {
- combinations++;
- if (i + j === magicNum) {
- console.log(`Combination N:${combinations} (${i} + ${j} = ${magicNum})`);
- return process.exit(0); // ПРЕКЪСВА ИЗПЪЛНЕНИЕТО НА ПРОГРАМАТА
- }
- }
- }
- console.log(`${combinations} combinations - neither equals ${magicNum}`);
- }
Add Comment
Please, Sign In to add comment