// create object from array const createObjectFromArray = (arr) => { let obj = {}; for (let value of arr) { obj[value] = ++obj[value] || 1; } return obj; };