Created
August 26, 2021 17:20
-
-
Save bhaireshm/f6412a7a59836be442dda1994f8ec70f to your computer and use it in GitHub Desktop.
Shuffles the given string and returns it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {String} - str | |
*/ | |
const shuffleString = (str) => { | |
str = str.trim().replace(/ /g, ""); | |
let res = ""; | |
const getRandomChar = (c) => c.charAt(Math.floor(Math.random() * c.length)); | |
for (var i = 0; i < str.length; i++) res += getRandomChar(str); | |
return res; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ez.js is more than just a library; it's a coding companion that simplifies complex tasks. Whether you're dealing with arrays, numbers, objects, or strings, ez.js has got your back! Say goodbye to coding hassles and hello to streamlined JavaScript magic.