Advertisement
teofarov13

Untitled

Mar 26th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function equalSumsEvenOddPosition(input) {
  2.     let firstNum = Number(input[0]);
  3.     let secondNum = Number(input[1]);
  4.     let print = ``
  5.     for (let i = firstNum; i < secondNum; i++) {
  6.         let currentNum = "" + i
  7.         let odd = 0;
  8.         let even = 0;
  9.         for (let j = 0; j < currentNum.length; j++) {
  10.             let curentDigit = Number(currentNum.charAt(j));
  11.             if (j % 2 === 0) {
  12.                 even += curentDigit;
  13.             } else {
  14.                 odd += curentDigit
  15.             }
  16.         }
  17.         if (odd === even) {
  18.             print += `${i} `
  19.         }
  20.     }
  21.     console.log(print)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement