showing results for - "find lucly iinteger arr"
Caterina
29 Feb 2020
1const findLucky = (arr) => {
2    let lucky = [-1];
3    let numObj = {};
4    for (num of arr) {
5        numObj[num] ? numObj[num] += 1 : numObj[num] = 1;
6    }
7    let nums = Object.keys(numObj); 
8    let frequencies = Object.values(numObj);
9    for (let num in nums) {
10        if (nums[num] == frequencies[num]) {
11            lucky.push(frequencies[num]);
12        }
13    }
14    if (lucky.length === 1) {
15        return lucky;
16    } else {
17        return Math.max(...lucky);
18    }
19};