js: update shuffle solution (typo)
parent
b01b4cbe79
commit
4ea3764d7a
|
@ -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']);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue