Skip to content

Instantly share code, notes, and snippets.

@haikelfazzani
Last active August 27, 2019 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haikelfazzani/ec609b23ef1385e92c4acfb0f5bfac85 to your computer and use it in GitHub Desktop.
Save haikelfazzani/ec609b23ef1385e92c4acfb0f5bfac85 to your computer and use it in GitHub Desktop.
/*
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