Advertisement
Guest User

08. Magic Sum - JS

a guest
Oct 17th, 2018
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. function solve(arr) {
  2. let sequence = arr[0].split(' ');
  3. for (let i = 0; i < sequence.length; i++) {
  4. sequence[i] = Number(sequence[i]);
  5. }
  6.  
  7. let magicSum = arr[1];
  8.  
  9. for (let i = 0; i < sequence.length - 1; i++) {
  10. let firstNum = sequence[i];
  11.  
  12. for (let j = i + 1; j < sequence.length; j++) {
  13. let secondNum = sequence[j];
  14.  
  15. if(firstNum + secondNum === magicSum) {
  16. console.log(`${firstNum} ${secondNum}`);
  17. }
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement