Liliana797979

Untitled

Nov 12th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function combinations(arr) {
  2. let combinations = 0;
  3. let combinationFound = false;
  4.  
  5. for (let i = 0; i < arr.length; i++) {
  6. arr[i] = Number(arr[i]);
  7. }
  8.  
  9. for (let i = (arr[0]); i <= arr[1]; i++) {
  10. for (let j = arr[0]; j <= Number(arr[1]); j++) {
  11. combinations++;
  12. if (i + j == arr[2]) {
  13. console.log(`Combination N:${combinations} (${i} + ${j} = ${arr[2]})`);
  14. combinationFound = true;
  15. break;
  16. }
  17. }
  18. if (combinationFound) {
  19. break;
  20. }
  21. if (!combinationFound) {
  22. console.log (`${combinations} - neither equals ${arr[2]}`);
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment