Last active
August 27, 2019 11:18
-
-
Save haikelfazzani/ec609b23ef1385e92c4acfb0f5bfac85 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
/* | |
reverse the string but without the index of the numbers. | |
Example: "he2llo" - "ol2leh" | |
Example: "De5ary4ou" - "uo5yra4eD" | |
Example: "D23amn5Boy" - "y23oBn5maD" | |
*/ | |
reverseNoNumbers = (a) => ( | |
v = a.match(/\D/g), | |
a.split``.map(i => /\D/.test(i) ? v.pop`` : i).join`` | |
) | |
/* | |
Join the first letter of each string in array | |
Example : ["Sarah", "Bmw"] => "SBamrwah" | |
*/ | |
favCarSplit = (a, i = 0, r = "") => { | |
while(i < Math.max(...a.map(e => e.length))) { | |
r += a.map(v=> v[i]).join`` | |
i++ | |
} | |
return r | |
} | |
/* | |
Examples : "abc 12" => "cba 21" // Great one!" => "taerG eno!" | |
*/ | |
recreateString = s => s.replace(/\w+/g, a => [...a].reverse().join``) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment