Because the algorithm is bad, so want to do a bit of this accumulation.
Try to learn a new algorithm every day. (But the estimate is very suspended)
Well, the first one today is the string conversion hump
Directly on the code
var str = ' toupper-case '; var arr = str.split ('-'); // toupper,case for (var i = 1; i < arr.length; i++) { // sets the first value of the array after the first array to uppercase and then the uppercase and the remaining characters of the first character to flatten arr[i] = Arr[i].charat (0). toUpperCase () + arr[i].slice (1); }; var str1 = Arr.join ("); // The Join method converts an array into a string ..... alert (STR1);
The second is to determine the number of occurrences of that letter in a string, and it appears several times.
varstr = ' AAAASSSSDDDDDDD ';varobj = {}; varnum = 0; varValue = '; for(vari = 0; i < str.length; i++) { if(!Obj[str[i]]) {Obj[str[i]]= []; } Else{Obj[str[i]].push (str[i]); } }; //var obj1 = { //' a ': [' a '], //' s ': [' s ', ' s ', ' s ', ' s ', ' s ', ' s '], //' d ': [' d ', ' d '] //}; for(varattrinchobj) { if(Num < Obj[attr].length) {//For the first time A has only one, then num = 1, the second s has n bits, then num = N, and the third d is less than n bits, then num or n //If there is no value greater than num then this value is the maximum number of letters that can be returned to the current num and valuenum =obj[attr].length; Value= Obj[attr][0]; } }; Alert (Value+ ', ' +num ')
Algorithm accumulation (string conversion hump, determine the number of occurrences of the letter in a string, and appear several times)