Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const array = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
- const getMostFrequentValue = array => {
- const countAllValues = array.reduce((acc, curr) => {
- if (curr in acc) {
- return { ...acc, [curr]: acc[curr] + 1 }
- }
- return { ...acc, [curr]: 1 }
- }, {})
- let matushkuEbalReduca = 0;
- let forRulitSuka = null;
- for (const value in countAllValues) {
- console.log(countAllValues[value], value);
- if (countAllValues[value] > x) {
- x = countAllValues[value];
- res = `key ${value} times ${countAllValues[value]}`
- }
- }
- return forRulitSuka;
- }
- console.log(getMostFrequentValue([0, 0, 1]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement