javascript/shuffle solution

best case solution: O(n)
pull/2/head
Raphael 2019-09-14 15:26:39 +02:00 committed by GitHub
parent 0e090ab706
commit 5aef1b4600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
function shuffle(string) {
const arr = this.split('');
const n = arr.length;
for(const i = n - 1; i >= 0; i--) {
cosnt j = Math.floor(Math.random() * (i + 1));
cosnt tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
return a.join('');
}
// Tests
/*describe("Solution", function() {
it("should find anagrams", function() {
Test.assertEquals(the quick brown fox jumps over the lazy dog".shuffle(), '');
});
});*/