I play a little with F # syntax .
In Sweden we have a game called "Backslang" (googletranslated from "Rövarspråk") The rules are pretty simple. All the words you say must be indicated in a certain way. Although the vocals are the same, each consonant must be pronounced with an “o” followed by a consonant.
those. "L" will be "LOL" , "FRIDAY" will be "FOFRORIDODAY" and "BALL" will be "BOBALOLLOL" .
I wrote code that looks really stupid but does its job.
let myWord (x:string) =
x.Replace("q","qoq").Replace("w","wow").Replace("r","ror").Replace("t","tot").Replace("p","pop").Replace("s","sos").Replace("d","dod").Replace("f","fof").Replace("g","gog").Replace("h","hoh").Replace("j","joj").Replace("k","kok").Replace("l","lol").Replace("z","zoz").Replace("x","xox").Replace("c","coc").Replace("v","vov").Replace("b","bob").Replace("n","non").Replace("m","mom").Replace("Q","QOQ").Replace("W","WOW").Replace("R","ROR").Replace("T","TOT").Replace("P","POP").Replace("S","SOS").Replace("D","DOD").Replace("F","FOF").Replace("G","GOG").Replace("H","HOH").Replace("J","JOJ").Replace("K","KOK").Replace("L","LOL").Replace("Z","ZOZ").Replace("X","XOX").Replace("C","COC").Replace("V","VOV").Replace("B","Bob").Replace("N","Non").Replace("M","Mom").ToLower()
myWord "ball"
F # Interactive: val it: string = "bobalollol"
For readability, is there a way to better understand this code?
I am new to F # and functional programming, so any tips, omissions and pointers are warmly welcome!