1、給你一個字符串,要你找出裡面出現次數最多的字母和出現的次數,例如:“abaasdffggghhjjkkgfddsssss”;
var str = "abaasdffggghhjjkkgfddsssss";
var arr = new Array();
var i = 0
while (str. charAt(0)) {
arr[i] = str.charAt(0) "=" (str.split(str.charAt(0)).length - 1);
str = str.split( str.charAt(0)).join("");
i ;
}
alert(arr);
for (var j = 0,temp=0; j if (temp temp = Number(arr[j].split("=")[ 1]);
i = j;
}
}
alert(arr[i]);
2、解字串的位元組長度;
var f = function(s) {
var f = function(s) {
if !arguments.length || !s) {
return null;
}
if ("" == s) {
return 0;
}
var l = 0;
for (var i = 0; i if (s.charCodeAt(i) > 255) {
l = 2;
} else {
l ;
}
}
alert(l);
};
f("你好a")
程式碼如下:
Array.prototype.strip = function.strip = function {strip = f
if (this.length return [this[0]] || [];
}
var arr = [];
for (var i = 0; i arr.push(this.splice(i--, 1));
for (var j = 0; j if (this[j] == arr[arr.length - 1]) {
this.splice(j--, 1);
}
}
}
return arr;
};
var a = ["abc", "abc", "a", "b", "c", "a", "b", "c"]; alert( a.strip());