- Ensure each of the test cases in the class Arrayutils successfully passes upon completion of each of the method stubs in the class ArrayutilsTest.
Integer getNumberOfOccurrences(Object[] objectArray, Object objectToCount)
Object[] removeValue(Object[] objectArray, Object objectToRemove)
Object getMostCommon(Object[] objectArray)
Object getLeastCommon(Object[] objectArray)
Object[] mergeArrays(Object[] objectArray, Object[] objectArrayToAdd)
- Description
- Given an array of objects of any
type
and anobject
of the sametype
, return the number of times theobject
occurs in the array.
- Given an array of objects of any
-
Sample Script
// Given Integer valueToEvaluate = 7; Integer expected = 3; Integer[] inputArray = {1, 2, 7, 8, 4, 5, 7, 0, 9, 8, 7}; // When Integer outcome = ArrayUtils.getNumberOfOccurrences(inputArray, valueToEvaluate); // Then System.out.println(outcome);
-
Sample Output
3
- Description
- Given an array of objects, named
objectArray
, and an objectobjectToCount
, return the number of times theobjectToCount
appears in theobjectArray
- Given an array of objects, named
-
Sample Script
// : Given Integer valueToRemove = 4; Integer[] inputArray = {5, 6, 4, 2, 9, 3, 0}; // : When Integer[] outcome = (Integer[]) ArrayUtils.removeValue(inputArray, valueToRemove); // : Then String outcomeStr = Arrays.toString(outcome); System.out.println(outcomeStr);
-
Sample Output
[5, 6, 2, 9, 3, 0]
- Description
- Given an array of objects, named
objectArray
return the most frequently occuring object in the array.
- Given an array of objects, named
-
Sample Script
// Given Integer expected = 1; Integer[] inputArray = {1,1,1,1,2,2,2,3,3,4}; // When Integer outcome = ArrayUtils.getMostCommon(inputArray); // Then System.out.println(outcome);
-
Sample Output
1
- Description
- Given an array of objects, named
objectArray
return the least frequently occuring object in the array.
- Given an array of objects, named
-
Sample Script
// Given Integer expected = 4; Integer[] inputArray = {1,1,1,1,2,2,2,3,3,4}; // When Integer outcome = ArrayUtils.getLeastCommon(inputArray); // Then System.out.println(outcome);
-
Sample Output
4
- Description
- given two arrays
objectArray
andobjectArrayToAdd
, return an array containing all elements inobjectArray
andobjectArrayToAdd
- given two arrays
-
Sample Script
// Given Integer[] objectArray = {1,1,1,2,2,2}; Integer[] objectArrayToAdd = {3,3,3,4,4,4}; // When Integer[] outcome = (Integer[]) ArrayUtils.mergeArrays(array1, array2); // Then String outcomeStr = Arrays.toString(outcome); System.out.println(outcomeStr);
-
Sample Output
[1,1,1,2,2,2,3,3,3,4,4,4]