Challenge
Write a function which takes an argument which is a verb, and returns the past tense of the verb. (Assume that the verb is regular)
Past tense
Note: consider y as neither consonant nor vowel.
Normally, just adding ed after the end of verb makes the past tense of the verb.
Ex: jump → jumped, ask → asked
However, there are other rules.
If the last character of the given verb is
e, just addd.Ex:
love→loved,move→movedIf the verb is ended with a consonant +
y, then changeytoi, and added.Ex:
study→studied,cry→criedHowever, if the verb is ended with a vowel +
y, then just added.Ex:
play→played,stay→stayedIf a verb is ended with a vowel and a consonant, then write the consonant one more time, and add
ed.Ex:
stop→stopped,plan→plannedHowever, if a verb is ended with multiple vowels + a consonant or single vowel + multiple consonants, then just add
ed.Ex:
look→looked,jump→jumped
There are more rules but let's care above rules only. For example, according to above rule, visit → visitted.
Winner
Since this is code golf, the shortest code that correctly returns past tenses wins.
Example (JS, 127)
function f(x){return x.replace(/([^aeiouy])y$/,'$1i').replace(/([^aeiouy][aeiou])([^aeiouy])$/,'$1$2$2').replace(/e$/,'')+'ed'}