File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ * More complex yet faster way to log "Hello World".
4
+ *
5
+ **/
6
+ let target = "hello world" ;
7
+ let index = 0 ;
8
+ let pointer = 0 ;
9
+ let ans = "" ;
10
+ let chars = "abcdefghijklmnopqrstuvwxyz" . split ( '' ) ;
11
+ let System = { out : { println : ( ...args ) => console . log ( ...args ) } } ;
12
+
13
+ function log ( char ) {
14
+ return new Promise ( resolve => {
15
+ setImmediate ( ( ) => {
16
+ let cur = target . split ( '' ) [ pointer ] ;
17
+
18
+ if ( cur === " " ) {
19
+ pointer ++ ;
20
+ ans += " " ;
21
+ }
22
+
23
+ if ( char === cur ) {
24
+ ans += char || " " ;
25
+ pointer ++ ;
26
+ }
27
+
28
+ let toLog = ans + char ;
29
+
30
+ System . out . println ( toLog . endsWith ( "dd" ) ? toLog . slice ( 0 , - 1 ) : toLog ) ;
31
+
32
+ if ( ans === target ) {
33
+ System . out . println ( "Successfully logged 'hello world!'" ) ;
34
+ process . exit ( ) ;
35
+ }
36
+
37
+ resolve ( ) ;
38
+ } ) ;
39
+ } ) ;
40
+ }
41
+
42
+ async function main ( ) {
43
+ while ( pointer < target . length ) {
44
+ let i = chars [ index ] ;
45
+ await log ( i ) ;
46
+ index = ( index + 1 ) % chars . length ;
47
+ }
48
+ }
49
+
50
+ main ( ) . catch ( err => console . error ( err ) ) ;
You can’t perform that action at this time.
0 commit comments