Finding a ‘Lucky Integer’
Given an array, find the greatest value who’s numbers frequency is the same number as itself.
Example:
Input: [1,1,2,2,3,3]
Output: 2
It’s important to divide and conquere when working on algorithmic codes. This problem requires 3 steps.
- Create a frequency table
- Sort array in decending order
- Iterate over the array until a hash key equals its value.
var findLucky = function(arr) {
let hash = {}…