Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Last active June 23, 2022 15:37
Show Gist options
  • Save Risyandi/6a788419eb1f7285852dce1a796fa241 to your computer and use it in GitHub Desktop.
Save Risyandi/6a788419eb1f7285852dce1a796fa241 to your computer and use it in GitHub Desktop.
how to get number triple using looping for.
/**
* 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