Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = [
- '4',
- '1',
- '3',
- '3',
- '7'
- ]
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let n = +gets();
- let newArr = [];
- let map = new Map();
- for (let i = 1; i <= n; i++) {
- let numb = +gets(); // convert string to number
- newArr.push(numb);
- if (map.has(numb)) {
- map.set(numb, map.get(numb) + 1);
- } else {
- map.set(numb, 1);
- }
- }
- let maxFreq = 0;
- let result = 0;
- for (let [num, freq] of map.entries()) {
- if (freq > maxFreq || (freq === maxFreq && num < result)) {
- maxFreq = freq;
- result = num;
- }
- }
- print(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement