js: update shuffle solution (typo)

pull/2/head
Raphael 2019-09-26 10:16:54 +02:00 committed by GitHub
parent b01b4cbe79
commit 4ea3764d7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 8 deletions

View File

@ -1,10 +1,9 @@
function shuffle(string) {
const arr = string.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];
for(const i = arr.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
@ -13,8 +12,19 @@ function shuffle(string) {
}
// Tests
/*describe("Solution", function() {
it("should shuffle string", function() {
Test.assertEquals(shuffle("the quick brown fox jumps over the lazy dog"), '');
describe("Solution", function() {
it("should not be the same string", function() {
const str = 'the quick brown fox jumps over the lazy dog';
Test.assertNotEquals(shuffle(str), str);
});
});*/
it("should stay the same string", function() {
const str = 'f';
Test.assertEquals(shuffle(str), str);
});
it("should shuffle string", function() {
const str = 'a b';
Test.assertIn(shuffle(str), ['a b', 'b a', ' ba', 'ba ', 'ab ', ' ab']);
});
});