Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16420

How to find the property which has the highest value

$
0
0
let obj1 = { 1:1,2:1,4:3};

I want to get the property 4 as the output because the value of that property is highest of all other properties. I am trying to find out the highest frequency number in my own way.

let arr1 = [1, 2, 3, 4, 4, 4, 5];let arr1Obj = {};function findMaxFreq(arr, arr1Obj) {  let freqArr = [];  let objarrvalue = 0;  for (let i = 0; i < arr.length; i++) {    let frequencyOf = arr[i];    let count = 1;    for (let j = arr[i]; j < arr.length; j++) {      if (arr[i] === arr[j]) {        count++;      } else {        break;      }    }    arr1Obj[arr[i]] = count;  }  let objvalues = Object.values(arr1Obj);  for (let i = 0; i < objvalues.length; i++) {    if (objvalues[i] > objarrvalue) {      objarrvalue = objvalues[i];    }  }  return objarrvalue;}console.log(findMaxFreq(arr1, arr1Obj));

Viewing all articles
Browse latest Browse all 16420

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>