about | help | code help+videos | done | prefs |
same
Using the function that returns the number of times an item occurs in an array, define a function that when passed two arrays, returns true if they contain the exact same items, even if in a different order, false otherwise. Return false if either array is null. int count(int[] data, int item) { int result = 0; for(int i=0; i < data.length; i++) { if(data[i] == item) { result++; } } return result; } same([10, 70, 20, 90], [90, 20, 10, 70]) → true same([1, 2, 3], [3, 1, 2]) → true same([10, 70, 20, 90], [90, 20, 20, 70]) → false ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 3 Post-solution available
Copyright Nick Parlante 2017 - privacy