Created
April 30, 2018 22:44
-
-
Save alexko30/55e86dec3a2ac83f1fa2f1eac6e8c14e to your computer and use it in GitHub Desktop.
automorphic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function automorphic(number) { | |
const numberArr = Array.from(number.toString()).map(Number); | |
const square = Math.pow(number, 2); | |
const squareArr = Array.from(square.toString()).map(Number); | |
const startElement = squareArr.length - numberArr.length; | |
let flag = false; | |
for (let i = 0, j = startElement; i < numberArr.length, j < squareArr.length; i++, j++) { | |
flag = false; | |
if (numberArr[i] == squareArr[j]) { | |
flag = true; | |
} else { | |
console.log(`${number} is not automorphic`); | |
break; | |
} | |
} | |
if (flag) { | |
console.log(`${number} is automorphic`); | |
} | |
} | |
automorphic(76); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment