Last active
June 23, 2022 15:37
-
-
Save Risyandi/6a788419eb1f7285852dce1a796fa241 to your computer and use it in GitHub Desktop.
how to get number triple using looping for.
This file contains hidden or 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
/** | |
* Risyandi - 2021 | |
* how to create increment to triple number. | |
* first we have value from looping with initial duplicate 3. | |
* and the expected result like this : | |
* 111 222 333 | |
* 111 222 333 | |
* 111 222 333 | |
* 444 555 666 | |
* 444 555 666 | |
* 444 555 666 | |
* 777 888 999 | |
* 777 888 999 | |
* 777 888 999 | |
*/ | |
function getNumberTriple(value) { | |
let result = ''; | |
let duplicate = 3; | |
for (let indexX = 0; indexX < duplicate; indexX++) { | |
let number = (indexX * 3); | |
for (let indexY = 0; indexY < duplicate; indexY++) { | |
for (let indexZ = 1; indexZ <= duplicate; indexZ++) { | |
let resNumber = (number + indexZ); | |
result += resNumber + ' ' + resNumber + ' ' + resNumber; | |
} | |
} | |
} | |
console.log(result); | |
return result; | |
} | |
getNumberTriple(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment