We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 47d821c commit 4b67bcaCopy full SHA for 4b67bca
functions/strings/str_shuffle.js
@@ -3,18 +3,16 @@ function str_shuffle (str) {
3
// + original by: Brett Zamir (http://brett-zamir.me)
4
// * example 1: shuffled = str_shuffle("abcdef");
5
// * results 1: shuffled.length == 6
6
- if (str == undefined) {
+ if (str == null) {
7
throw 'Wrong parameter count for str_shuffle()';
8
}
9
+
10
+ str += '';
11
- var getRandomInt = function (max) {
- return Math.floor(Math.random() * (max + 1));
12
- };
13
- var newStr = '',
14
- rand = 0;
+ var newStr = '', rand;
15
16
while (str.length) {
17
- rand = getRandomInt(str.length - 1);
+ rand = Math.floor(Math.random() * str.length);
18
newStr += str.charAt(rand);
19
str = str.substring(0, rand) + str.substr(rand + 1);
20
0 commit comments