🔤String
🚧 under construction -> move 💾 程式
// ⭐️ string.random()
// ⭐️ Note: this may not work well with Unicode❗️
String.prototype.random = function(){
return this[randomInt(this.length)];
}
// ⭐️ string.shuffle()
String.prototype.shuffle = function(){
var a = this.split("");
var n = a.length;
for(var i = n - 1; i > 0; i--) {
var j = randomInt(i+1);
[a[i], a[j]] = [a[j], a[i]];
}
return a.join("");
}
// ⭐️ String.fromCharCodesBetween(65, 70) -> 'ABCDEF'
String.fromCharCodesBetween = function(from, to){
let array = [];
for(let i = from; i <= to; i++) array.push(i);
return array
.map(code => String.fromCharCode(code))
.join('');
};Last updated