File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function countdown ( n : number ) : void {
2+ for ( let i = n ; i >= 0 ; i -- ) {
3+ console . log ( i ) ;
4+ }
5+ console . log ( "Liftoff!" ) ;
6+ }
7+
8+ function countdownRecursive ( n : number ) : void {
9+ console . log ( n ) ;
10+ if ( n === 0 ) {
11+ console . log ( "Liftoff!" ) ;
12+ return ;
13+ }
14+ countdownRecursive ( n - 1 ) ;
15+ }
Original file line number Diff line number Diff line change 1+ def factorial ( number )
2+ if number == 1
3+ return 1
4+ else
5+ return number * factorial ( number - 1 )
6+ end
7+ end
Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
3+
4+ function findDirectories ( directory ) {
5+ const entries = fs . readdirSync ( directory ) ;
6+
7+ for ( const entry of entries ) {
8+ const fullPath = path . join ( directory , entry ) ;
9+ if ( fs . statSync ( fullPath ) . isDirectory ( ) && entry !== '.' && entry !== '..' ) {
10+ console . log ( fullPath ) ;
11+
12+ const innerEntries = fs . readdirSync ( fullPath ) ;
13+ for ( const innerEntry of innerEntries ) {
14+ const innerPath = path . join ( fullPath , innerEntry ) ;
15+ if ( fs . statSync ( innerPath ) . isDirectory ( ) && innerEntry !== '.' && innerEntry !== '..' ) {
16+ console . log ( innerPath ) ;
17+ }
18+ }
19+ }
20+ }
21+ }
22+
23+ function findDirectoriesRecursive ( directory ) {
24+ const entries = fs . readdirSync ( directory ) ;
25+
26+ for ( const entry of entries ) {
27+ const fullPath = path . join ( directory , entry ) ;
28+ if ( fs . statSync ( fullPath ) . isDirectory ( ) && entry !== '.' && entry !== '..' ) {
29+ console . log ( fullPath ) ;
30+ findDirectoriesRecursive ( fullPath ) ;
31+ }
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ def find_directories ( directory ) # only works for two levels deep
2+ Dir . foreach ( directory ) do |filename |
3+ if File . directory? ( "#{ directory } /#{ filename } " ) && filename != '.' && filename != '..'
4+ puts "#{ directory } /#{ filename } "
5+ Dir . foreach ( "#{ directory } /#{ filename } " ) do |inner_filename |
6+ if File . directory? ( "#{ directory } /#{ filename } /#{ inner_filename } " ) && inner_filename != '.' && inner_filename != '..'
7+ puts "#{ directory } /#{ filename } /#{ inner_filename } "
8+ end
9+ end
10+ end
11+ end
12+ end
13+
14+ def find_directories_recursive ( directory ) # works for any depth
15+ Dir . foreach ( directory ) do |filename |
16+ if File . directory? ( "#{ directory } /#{ filename } " ) && filename != '.' && filename != '..'
17+ puts "#{ directory } /#{ filename } "
18+ find_directories_recursive ( "#{ directory } /#{ filename } " )
19+ end
20+ end
21+ end
Original file line number Diff line number Diff line change 1+ def sum ( low , high )
2+ if low == high
3+ return low
4+ else
5+ return high + sum ( low , high - 1 )
6+ end
7+ end
Original file line number Diff line number Diff line change 1+ const array = [
2+ 1 ,
3+ 2 ,
4+ 3 ,
5+ [ 4 , 5 , 6 ] ,
6+ 7 ,
7+ [
8+ 8 ,
9+ [
10+ 9 , 10 , 11 ,
11+ [ 12 , 13 , 14 ]
12+ ]
13+ ] ,
14+ [
15+ 15 , 16 , 17 , 18 , 19 ,
16+ [
17+ 20 , 21 , 22 ,
18+ [
19+ 23 , 24 , 25 ,
20+ [ 26 , 27 , 29 ]
21+ ] ,
22+ 30 , 31
23+ ] ,
24+ 32
25+ ] ,
26+ 33
27+ ]
28+
29+ function printArray ( arr ) {
30+ arr . forEach ( item => {
31+ if ( ! Array . isArray ( item ) ) {
32+ console . log ( item ) ;
33+ } else {
34+ printArray ( item ) ;
35+ }
36+ } )
37+ }
You can’t perform that action at this time.
0 commit comments