P4 Part 2

Run Settings
LanguageF#
Language Version
Run Command
/// Takes in a key x and a head value (y,z) to see if x and y are equal let checkChar (x: string) ((y,z): string*int) = if x = y then true else false /// Takes in a head value (a,b) and returns only b let getChar ((a,b): string*int) = b /// Takes in a key value x and a list of (string*int) values and gets int values /// of list items that match the given key let rec getListMatches x list = if list = [] then [] else let hd :: tl = list // see if current hd values match key if (checkChar x hd) then // get the integer value from current hd and append to list getChar hd :: getListMatches x tl // otherwise ignore currnet hd and continue to rest of list else getListMatches x tl /// Function to call getListMatches and sort the resulting list let findMatches x list = let matchlist = getListMatches x list // sort the integers that match the key from previous function call let result = List.sort matchlist result let matchlist = [("A",5); ("BB",6); ("AA",9); ("A",0)] printfn "%A is matchlist" matchlist let result = findMatches "A" matchlist printfn "%A is result" result
Editor Settings
Theme
Key bindings
Full width
Lines