陳鍾誠

Version 1.0

逐字翻譯程式

執行結果

PS D:\ccc\book\aijs\code\07-language> node e2c a dog chase a cat
[ '一隻', '狗', '追', '一隻', '貓' ]
PS D:\ccc\book\aijs\code\07-language> node e2c the cat eat a dog
[ undefined, '貓', '吃', '一隻', '狗' ]
PS D:\ccc\book\aijs\code\07-language> node e2c that cat eat a dog
[ '那隻', '貓', '吃', '一隻', '狗' ]
PS D:\ccc\book\aijs\code\07-language> node e2c that cat chase the cat
[ '那隻', '貓', '追', '這隻', '貓' ]

程式碼 e2c.js

var e2c = { dog:'狗', cat:'貓', a: '一隻', the: '這隻', that:'那隻', chase:'追', eat:'吃' }

function mt(e) {
  var c = []
  for (i in e) {
    var eword = e[i]
    var cword = e2c[eword]
    c.push(cword)
  }
  return c
}

var c = mt(process.argv.slice(2))
console.log(c)