Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let store = JSON.parse(localStorage.getItem('store') || '{}');
- const parse = () => {
- store = [...document.querySelectorAll('.haplo0, .haplo1')].map(el => el.innerText[0]).filter(h => /\w/.test(h)).reduce((a, i) => a[i] ? {...a, [i]: a[i] + 1} : {...a, [i]: 1}, store);
- localStorage.setItem('store', JSON.stringify(store));
- }
- const clear = () => {
- localStorage.removeItem('store');
- store = {};
- }
- const calc = () => {
- const len = Object.entries(store).reduce((a, i) => a + i[1], 0);
- return Object.entries(store).map((e) => [e[0], (e[1] / len * 100).toFixed(2) + '%']).reduce((a, i) => ({...a, [i[0]]: i[1]}), {});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement