Преглед изворни кода

finished GetNumberOfOccurrencesTest

Luis Romero пре 6 година
родитељ
комит
49522bf904
1 измењених фајлова са 31 додато и 3 уклоњено
  1. 31
    3
      src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java

+ 31
- 3
src/main/java/com/zipcodewilmington/arrayutility/ArrayUtility.java Прегледај датотеку

@@ -2,6 +2,7 @@ package com.zipcodewilmington.arrayutility;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 import java.util.Arrays;
5
+import java.util.HashMap;
5 6
 
6 7
 /**
7 8
  * Created by leon on 3/6/18.
@@ -33,10 +34,37 @@ public class ArrayUtility<E> {
33 34
     }
34 35
 
35 36
     public int getNumberOfOccurrences(E valueToEvaluate) {
36
-        return 0;
37
+        int count = 0;
38
+        for (E element : inputArray) {
39
+            if (element == valueToEvaluate) {
40
+                count++;
41
+            }
42
+        }
43
+        return count;
37 44
     }
38 45
 
39
-
40
-
46
+//    public int getMostCommonFromMerge(E valueToEvaluate) {
47
+//
48
+//        Object mostCommonNum = null;
49
+//        int mostOccurrences = 0;
50
+//
51
+//        HashMap<Object, Integer> hashMap = new HashMap<>();
52
+//
53
+//        for (Object object : objectArray) {
54
+//            if (!hashMap.containsKey(object)) {
55
+//                hashMap.put(object, 1);
56
+//            } else {
57
+//                hashMap.put(object, hashMap.get(object) + 1);
58
+//            }
59
+//
60
+//            if (hashMap.get(object) > mostOccurrences) {
61
+//                mostCommonNum = object;
62
+//                mostOccurrences = hashMap.get(object);
63
+//            }
64
+//        }
65
+//
66
+//        System.out.println(mostCommonNum);
67
+//        return mostCommonNum;
68
+//    }
41 69
 
42 70
 }