File tree 1 file changed +7
-9
lines changed
1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 1
1
import * as io from '../utils/io.js'
2
2
3
3
const map = {
4
+ ' ' : '0' ,
4
5
'a' : '2' ,
5
6
'b' : '22' ,
6
7
'c' : '222' ,
@@ -26,11 +27,12 @@ const map = {
26
27
'w' : '9' ,
27
28
'x' : '99' ,
28
29
'y' : '999' ,
29
- 'z' : '9999' ,
30
- ' ' : '0'
30
+ 'z' : '9999'
31
31
}
32
+
32
33
const charToDigit = char => map [ char ]
33
- const spacing = ( prev , current ) => {
34
+
35
+ const joinWithSpace = ( prev , current ) => {
34
36
const prevChar = prev [ prev . length - 1 ]
35
37
const nextChar = current [ 0 ]
36
38
if ( prevChar === nextChar ) {
@@ -43,14 +45,10 @@ const notEmpty = (line) => line && line.length
43
45
44
46
const formatLine = ( line , index ) => `Case #${ index + 1 } : ${ line } `
45
47
46
- export const convertLine = ( line ) => Array . from ( line ) . map ( charToDigit ) . reduce ( spacing , '' )
48
+ export const convertLine = ( line ) => Array . from ( line ) . map ( charToDigit ) . reduce ( joinWithSpace , '' )
47
49
48
50
export const convertMulti = ( input ) => input . split ( '\n' ) . slice ( 1 ) . filter ( notEmpty ) . map ( convertLine )
49
51
50
52
export const convert = ( input ) => convertMulti ( input ) . map ( formatLine ) . join ( '\n' )
51
53
52
- export default ( file ) => io . readAsString ( file ) . then ( input => {
53
- const output = convert ( input )
54
- console . log ( output )
55
- io . writeFile ( output )
56
- } )
54
+ export default ( file ) => io . readAsString ( file ) . then ( convert ) . then ( io . writeFile )
You can’t perform that action at this time.
0 commit comments