TZinovieva

Magic Sum

Jan 28th, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function magicSum(arr, num) {
  2.    
  3.     for (let i = 0; i < arr.length; i++) {
  4.         let currentNum = arr[i];
  5.        
  6.         for (let j = i + 1; j < arr.length; j++) {
  7.             let nextNum = arr[j];
  8.    
  9.             if (currentNum + nextNum === num) {
  10.             console.log(currentNum + ' ' + nextNum);
  11.             }
  12.         }
  13.     }  
  14. }
Advertisement
Add Comment
Please, Sign In to add comment