I find a website has some method and explanations, I just feel all those simplest methods it’s a bit hard for me, but I wanna good at that algorithm.
e.g
Pig Latin
link: https://www.freecodecamp.org/challenges/pig-latin
simple way:
function translate(str)
var vowelIndex = /[aeiou]/.exec(str).index;
return str.slice(vowelIndex) + (str.substr(0, vowelIndex) || “w”) + “ay”;
}
hard way ES5:
function translate(str) {
return str.replace(/(\w*?)([aeiou])(\w*)/, function (_, before, vowel, after) {
return vowel + after + before || “w” + ay;
})
}
Diffrent form ES6:
function translate(str) {
return str.replace(/(\w*?)([aeiou])(\w*)/, (_, before, vowel, after) => ${vowel}${after}${before || "w"}ay);
}
If I choose to understand those hard way, it will take me a lot of time. So I wanna improve those basic first, But I don’t know If I’m right or not?
At the same time, I wanna spend more time to figure those problems by myself, but it just too hard for me. The weird thing was I can saw other people do always spend a lot of time for those seems, they alway can found some special way by themselves, Should I do that?
you picked up new pattern or methods one by one along the way.
there is always more than one way to solve a problem… so it would be difficult to find every way to solve a problem.
is good to find different way to do it… but no need to get stressed out about it.
everyone learned bit by bit … and eventually knows a language better.
so take your time, learn new pattern/method when you feel insterested. and just save em to read in the future if it’s too difficult to understand.
at least that’s what i would do
I think even seasoned professional will require a bit of time to understand what it does.
My advice is don’t spend too much time diving into regex as a beginner.
Watch this video, it’ll give you regex basics that will be enough for most cases: