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