Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
610 B
1
Indexable
Never
const transactions = [
  'Omega', 'Alpha', 'Omega',
  'Alpha', 'Omega', 'Alpha',
  'Omega', 'Alpha', 'Omega',
  'Alpha', 'Omega', 'Alpha',
  'Omega', 'Alpha', 'Omega',
  'Alpha', 'Omega', 'Alpha',
  'Omega', 'Beta'
]


function count(transactions) {
  const map = {}
  for (const transaction of transactions) {
    const [count] = transaction;
    if (!map[transaction]) {
      map[transaction] = {
        count: 1,
      };
      continue;
    }

    map[transaction].count += 1
  }

  for (const transaction in map) {
    console.log(map[transaction].count / transactions.length)
  }
}

count(transactions)