Last active
May 5, 2022 18:19
-
-
Save andycmaj/7e540f047546bf61a4c78b245f4e9545 to your computer and use it in GitHub Desktop.
This file contains 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
export const problem1 = function (length = 12) { | |
let result = ""; | |
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
const charactersLength = characters.length; | |
for (let i = 0; i < length; i++) { | |
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
} | |
return result; | |
}; |
This file contains 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
export const problem2 = (str: string) => { | |
return str.replace(/[^a-zA-Z0-9-]/g, "-").toLowerCase(); | |
}; | |
This file contains 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
export const prob3_a = (e) => { | |
return e.replace(/_([a-z])/g, (g) => g[1].toUpperCase()); | |
}; | |
export const prob3_b = (e) => { | |
return e.match(/([A-Z])/g).reduce( | |
(str, c) => str.replace(new RegExp(c), '_' + c.toLowerCase()), | |
e | |
) | |
.substring((e.slice(0, 1).match(/([A-Z])/g)) ? 1 : 0); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment