haikelfazzani
8/26/2019 - 1:07 PM

code-challenges.js

/*
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``)