title: There is an int array with several numbers in it. How many different numbers are required to be counted? How often are each number appearing? The array is arranged from less to more frequency, the same frequency is from small to large.
Workaround: Use an array to store different numbers and occurrence probabilities, compare the numbers in each group with the other numbers in the group, and set the same one to NULL, as well as the number of occurrences of the numbers plus 1, and finally use the bubble sort
JS Implementation code:
varnumberdata=[1,4,5,7,8,3,1,6,4,8,4,6,9,410, A, the, A,6, -, A,5,7,8,5,2,4,1,5,6,3,Ten]; function countnumberarray(){ varResult=[]; result[0]=[]; result[1]=[];varalldisnum=0;varindex=0;//Statistics of different numbers for(vari = numberdata.length-1; I >=0; i--) {varTemp=numberdata[i];if(temp) {result[0][index]=temp; result[1][index]=1; for(varj = numberdata.length-1; J >=0; j--) {if(temp==numberdata[j]&&j!=i) {result[1][index]+=1; numberdata[j]=NULL; }} index++; } }//Sort for(vari =0; I <result[1].length-1; i++) { for(varj=i+1; j<result[1].length;j++) {varfcnt=result[1][i];varfnum=result[0][i];if(fcnt>result[1][j]| (fcnt==result[1][j]&&fnum>result[0][J])) {result[1][i]=result[1][J]; result[1][j]=fcnt; result[0][i]=result[0][J]; result[0][j]=fnum; } } }}
Front-end written questions practice notes: Statistics The probability of the occurrence of different numbers in an array and sorts