Skip to content
Permalink
c33b19b8ca
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
25 lines (22 sloc) 557 Bytes
'use strict'
const data = new Map()
const readline = require('readline-sync')
let input
do {
input = String(readline.question('enter command: ')).trim()
debugger
if (input.indexOf('add ') === 0) {
const space = input.indexOf(' ')
const item = input.substring(space).trim()
console.log(`adding '${item}'`)
let qty = 1
debugger
if (data.has(item)) qty = data.get(item)
data.set(item, qty)
}
if (input.indexOf('list') === 0) {
data.forEach( (val, key) => {
process.stdout.write(`${key}\t${val}\n`)
})
}
} while (input !== 'exit')