Assign values at desired place in the matrix
for ( let i = 0 ; i < n - 1 ; i ++ ) { matrix [ i ] [ u ] = i + 1 ; for ( let j = 1 ; j < n / 2 ; j ++ ) { let a = ( i + j ) % ( n - 1 ) ; let b = ( i - j + n - 1 ) % ( n - 1 ) ; if ( a < b ) { let temp = a ; a = b ; b = temp } matrix [ b ] [ a ] = i + 1 ; } }