1

This is the example of the required output :

1 2 3 4 5 6 7 8 9 0 
2 3 4 5 6 7 8 9 0 1 
3 4 5 6 7 8 9 0 1 2
4 5 6 7 8 9 0 1 2 3
5 6 7 8 9 0 1 2 3 4
6 7 8 9 0 1 2 3 4 5
7 8 9 0 1 2 3 4 5 6
8 9 0 1 2 3 4 5 6 7
9 0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9

This is what I have written so far :

for (var nam = 9; nam > 0; nam--){ 
    for (var x = 1 ; x <= 9; x++){
       if (x == nam){
        process.stdout.write(x +" 0 ");
       } else {
        process.stdout.write(x + " ");
       }
    }
    console.log();
}

2
  • 1
    What did you try? Commented Nov 29, 2017 at 18:36
  • 1
    Don't post code in the comment section. Instead edit your question to add it.(and don't forget to format it properly) Commented Nov 29, 2017 at 18:37

1 Answer 1

1

You could use nested for loops and take the remainder operator for adjusting the value of outer and inner counter.

var i, j, array;

for (i = 1; i <= 10; i++) {
    array = [];
    for (j = 0; j < 10; j++) {
        array.push((j + i) % 10);
    }
    console.log(array.join(' '));
}
.as-console-wrapper { max-height: 100% !important; top: 0; }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.