“JavaScript Shuffle String” Ответ

Перетасовать укус в JavaScript

var shuffled = str.split('').sort(function(){return 0.5-Math.random()}).join('');
Brave Bug

JavaScript Shuffle String

String.prototype.shuffle = function () {
    var a = this.split(""),
        n = a.length;

    for(var i = n - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
    return a.join("");
}
console.log("the quick brown fox jumps over the lazy dog".shuffle());
//-> "veolrm  hth  ke opynug tusbxq ocrad ofeizwj"

console.log("the quick brown fox jumps over the lazy dog".shuffle());
//-> "o dt hutpe u iqrxj  yaenbwoolhsvmkcger ozf "
Worrisome Wallaby

Ответы похожие на “JavaScript Shuffle String”

Вопросы похожие на “JavaScript Shuffle String”

Смотреть популярные ответы по языку

Смотреть другие языки программирования