logo
Search
showing results for - "find lucky integer in javascript"
Elisa
04 Jan 2020
1const findLucky = function(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};
similar questions
javascript biggest numberfind a number that is closest to a specific number in javascriptjavascript number between valuesfind positive integers javascriptdistinguishing positive numbers in javascriptlog odd numbers jshow to tell this x 3d 12 2b 30 when i read it in jsjavascript find the min in array of numbershow to calculate number with arithmetic operators in javascriptjavascript max safe integerjavascript lowest numberprimitive numbers javascript coding sample increas by 1js return the highest and lowest numberjs find lowest number in arrayjavascript performing an integer divisionhow to use the ceil 28 29 method to calculate the smallest integer greater than or equal to 43 8 in javascripthow to show 1 to 10 odd numbers in javascriptbiggest number javascript
queries leading to this page
javascript find lucky numberfind lucky integer in javascriptfind lucky number jsfind lucky integer in javascript
privacy policyterms of useinstagram
Crafted with  ♥  for everyone

sign in to continue
your answer for
you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content
please ensure to add code which is syntactically corrent and executes properly
sign in to continue
ask question on maxinterview
you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content
please be clear, to the point and respectful
sign in to continue