We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eea2633 commit 5942d4eCopy full SHA for 5942d4e
Medium Difficulty/simpleMode3.js
@@ -0,0 +1,35 @@
1
+// coderbyte solution for simple mode
2
+// splashinn
3
+
4
+function countFrequency(arr) {
5
+ var obj = {};
6
+ for (var i = 0; i < arr.length; i++) {
7
+ var element = arr[i];
8
+ var value = obj[element];
9
+ if (value === undefined) {
10
+ obj[element] = 1;
11
+ } else {
12
+ obj[element] = value + 1;
13
+ }
14
15
+ return obj;
16
+}
17
18
+function finalMaximum(obj) {
19
+ var max = 0;
20
+ var mode = undefined;
21
+ for (var key in obj) {
22
+ var value = obj[key];
23
+ if (value > max) {
24
+ max = value;
25
+ mode = key;
26
27
28
+ return parseInt(mode);
29
30
31
+function SimpleMode(arr) {
32
+ var obj = countFrequency(arr);
33
+ var mode = finalMaximum(obj);
34
+ return mode;
35
0 commit comments