Last active
March 28, 2023 14:20
-
-
Save salmanx/805ec1aabac4dedd3827a03952cce246 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
const str = "cats AND*Dogs-are Awesome"; | |
// const str = 'a b c d-e-f%g' | |
const splitted_word = str.split(/\W+/); | |
const result = | |
splitted_word[0].toLocaleLowerCase() + | |
splitted_word | |
.slice(1) | |
.slice(-splitted_word.length) | |
.map((s) => s.charAt(0).toUpperCase() + s.slice(1).toLocaleLowerCase()) | |
.join(""); | |
console.log(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
# Have the function `StringChallenge(**str**)` take the **str** parameter being passed and return it in proper camel case format where the first letter of each word is capitalized (excluding the first letter). | |
# The string will only contain letters and some combination of delimiter punctuation characters separating each word. | |
# For example: if **str** is "BOB loves-coding" then your program should return the string **bobLovesCoding**. | |
# Once your function is working, take the final output string and intersperse it character-by-character with your ChallengeToken. | |
# Your ChallengeToken: **r1omjb4zc8f** | |
# Input: "cats AND*Dogs-are Awesome" | |
# Output: catsAndDogsAreAwesome | |
# After interparse Final Output: cra1tosmAjnbd4Dzocg8sfAreAwesome | |
# Input: "a b c d-e-f%g" | |
# Output: aBCDEFG | |
# After interparse Final Output: arB1CoDmEjFbG4zc8f | |
str = "cats AND*Dogs-are Awesome" | |
# str = "a b c d-e-f%g" | |
delimeters = [' ', '*', '-', '%'] | |
splitted_word = str.split(Regexp.union(delimeters)) | |
# splitted_word = str.split(/\W+/); | |
camel_cased_word = splitted_word.last(splitted_word.length - 1 ).map { |a| a.capitalize }.unshift(splitted_word.first.downcase).join | |
puts camel_cased_word | |
token = "r1omjb4zc8f" | |
a1 = camel_cased_word.split('') | |
b1 = token.split('') | |
interspersed_word = "" | |
if a1.length < b1.length | |
interspersed_word = a1.zip(b1.shift(a1.length)) + b1 | |
elsif a1.length > b1.length | |
interspersed_word = a1.shift(b1.length).zip(b1) + a1 | |
else | |
interspersed_word = a1.zip(b1) | |
end | |
puts interspersed_word.flatten.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment