Skip to content

Commit f3f2d7a

Browse files
author
pasit.r
committed
refactor and cleanup
1 parent 2be48a7 commit f3f2d7a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/spelling/t9.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as io from '../utils/io.js'
22

33
const map = {
4+
' ': '0',
45
'a': '2',
56
'b': '22',
67
'c': '222',
@@ -26,11 +27,12 @@ const map = {
2627
'w': '9',
2728
'x': '99',
2829
'y': '999',
29-
'z': '9999',
30-
' ': '0'
30+
'z': '9999'
3131
}
32+
3233
const charToDigit = char => map[char]
33-
const spacing = (prev, current) => {
34+
35+
const joinWithSpace = (prev, current) => {
3436
const prevChar = prev[prev.length - 1]
3537
const nextChar = current[0]
3638
if (prevChar === nextChar) {
@@ -43,14 +45,10 @@ const notEmpty = (line) => line && line.length
4345

4446
const formatLine = (line, index) => `Case #${index + 1}: ${line}`
4547

46-
export const convertLine = (line) => Array.from(line).map(charToDigit).reduce(spacing, '')
48+
export const convertLine = (line) => Array.from(line).map(charToDigit).reduce(joinWithSpace, '')
4749

4850
export const convertMulti = (input) => input.split('\n').slice(1).filter(notEmpty).map(convertLine)
4951

5052
export const convert = (input) => convertMulti(input).map(formatLine).join('\n')
5153

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)

0 commit comments

Comments
 (0)