Advertisement
Liliana797979

viarno reshenie special numbers

Feb 16th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function specialNumbers(input) {
  2.     let n = Number(input[0]);
  3.  
  4.     let output = "";
  5.     for (let currentNumber = 1111; currentNumber <= 9999; currentNumber++) {
  6.         let currentNumberAsText = currentNumber.toString();
  7.         let firstDigit = Number(currentNumberAsText[0]);
  8.         let secondDigit = Number(currentNumberAsText[1]);
  9.         let thirdDigit = Number(currentNumberAsText[2]);
  10.         let fourthDigit = Number(currentNumberAsText[3]);
  11.  
  12.         let firstIsMagic = n % firstDigit === 0;
  13.         let secondIsMagic = n % secondDigit === 0;
  14.         let thirdIsMagic = n % thirdDigit === 0;
  15.         let fourthIsMagic = n % fourthDigit === 0;
  16.  
  17.         if (firstIsMagic && secondIsMagic && thirdIsMagic && fourthIsMagic) {
  18.             output += currentNumber + " ";
  19.         }
  20.  
  21.     }
  22.     console.log(output);
  23. }
  24.  
  25. specialNumbers(["3"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement