I'm attempting a Javascript challenge from codewars regarding replacing strings.
The instructions are: Your Task :
You have to create a function GrεεκL33t which
takes a string as input and returns it in the form of
(L33T+Grεεκ) Case.
Note: The letters which are not being converted in
(L33T+Grεεκ) Case should be returned in the lowercase.
(L33T+Grεεκ)Case:
A=α (Alpha) B=β (Beta) D=δ (Delta)
E=ε (Epsilon) I=ι (Iota) K=κ (Kappa)
N=η (Eta) O=θ (Theta) P=ρ (Rho)
R=π (Pi) T=τ (Tau) U=μ (Mu)
V=υ (Upsilon) W=ω (Omega) X=χ (Chi)
Y=γ (Gamma)
Examples:
GrεεκL33t("CodeWars") = "cθδεωαπs"
GrεεκL33t("Kata") = "κατα"
I think the problem is that when I copy the greek characters provided on the web page codewars can't recognise them, it evaluates to:
Expected: cθδεωαπs, instead got: cundefinedundefinedundefinedundefinedundefinedundefineds
My solution is below, anyone have any idea how to get it working?
function GrεεκL33t(str){
var mapObj = {
A:"α", B:"β", D:"δ",E:"ε", I:"ι", K:"κ",
N:"η", O:"θ", P:"ρ", R:"π", T:'τ', U:'μ',
V:'υ', W:'ω', X:'χ', Y:'γ'
};
str = str.replace(/A|B|D|E|I|K|N|O|P|R|T|U|V|W|X|Y/gi, function(matched){
return mapObj[matched];
});
return str;
}
matchedis not what you think it is. Read the documentation forreplace()to learn what parameters it passes.The letters which are not being converted in (L33T+Grεεκ) Case should be returned in the lowercase.I copy the greek characters provided on the web page codewars can't recognise them, it evaluates toIf you run your code in the console, you'll see it's not codewars that's the problem. It's your code.