How to learn Pattern printing easily ? | JavaScript implementation of the approach
var N = 4 , i , j , min ; document . write ( " " + N + " " ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } document . write ( " " ) ; } for ( i = N - 1 ; i >= 1 ; i -- ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } for ( j = N - 1 ; j >= 1 ; j -- ) { min = i < j ? i : j ; document . write ( N - min + 1 ) ; } document . write ( " " ) ; }