Advertisement
miroLLL

Magic Sum

Jun 5th, 2020
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function magicSum(array, magicNumber) {
  2.  
  3.     let result = [];
  4.  
  5.     for (let i = 0; i < array.length; i++) {
  6.  
  7.         let currentElement = array[i];
  8.  
  9.         for (let index = i + 1; index < array.length; index++) {
  10.  
  11.             let nextElement = array[index];
  12.             let isMagic = (currentElement + nextElement) === magicNumber;
  13.  
  14.             if ((isMagic)) {
  15.                 result.push(`${currentElement} ${nextElement}`);
  16.             }
  17.         }
  18.     }
  19.  
  20.     console.log(result.join('\n'));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement