const list = () => {
	let prevData
	try {
		prevData = localStorage.getItem('score')
		prevData = JSON.parse(prevData)
	} finally {
		prevData = prevData || []
	}

	return prevData
}

const add = (row) => {
	const prevData = list()
	prevData.push(row)
	prevData.sort((a, b) => b.total - a.total)
	localStorage.setItem('score', JSON.stringify(prevData.slice(0, 10)))
}

export default {
	list, add
}
