Array de-weight and sort:
var arr = [1,5,1,2,6,8,1,81,9,0];for (var i=0;i<arr.length;i++) {for (Var j=i+1;j<arr.length;j++) {if (arr[i] = = Arr [j]) {Arr.splice (j,1); j--;}}} Arr.sort (A, b) {return a-b;//from small to Large}) alert (arr);//0,1,2,5,6,8,9,81arr.sort (function (A, b) {return b-a;// From large to small sort}) alert (arr);//81,9,8,6,5,2,1,0
Random number between 0~10:
Alert (Math.Round (Math.random () *10));
Math.random () random decimals between 0~1
Math.Round () rounding
The most occurrences of characters and times in a string:
var str = ' Ssaaaasdfssszsssaaw '; function test (str) {var obj = {};var num = 0;var value = '; for (Var i=0;i<str.length;i++ {if (!obj[str[i]]) {obj[str[i]] = [];} Obj[str[i]].push (Str[i]);} for (var attr in obj) {if (num<obj[attr].length) {num = Obj[attr].length;value = Obj[attr][0];}} Return ' The most characters are: ' +value+ ', appeared: ' +num+ ';} Alert (Test (str))
Array de-weight and sorting/0~10 random numbers/characters and times in a string