Skip to content
Permalink
f1a05b0083
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
35 lines (29 sloc) 681 Bytes
'use strict'
let data = []
module.exports.clear = () => {
if(data.length === 0) throw new Error('trying to clear empty list')
data = []
}
module.exports.add = (item, qty) => {
item = item.toLowerCase()
if(item.length === 0) {
throw new Error('item is blank string')
}
if (typeof qty !== 'number') qty = 1
let listItem = data.find(elem => elem.item==item)
if (listItem) {
listItem.qty +=qty
}
else {
data.push({item: item, qty: qty})
}
}
module.exports.getAll = () => {
if(data.length === 0) throw new Error('empty list')
for(const key in data) data[key].key = key
return data
}
module.exports.delete = key => {
console.log(`delete key ${key}`)
return
}