DEV Community

Discussion on: Daily Challenge #121 - Who has the most money?

Collapse
 
peterbunting profile image
Peter Bunting • Edited

My first attempt at F#

type Student(name,fives,tens,twenties) =
    member this.Name: string = name
    member this.Fives: int = fives
    member this.Tens: int = tens
    member this.Twenties: int = twenties
    member this.getStudentAmount  with get () = (this.Fives * 5) + (this.Tens * 10) + (this.Twenties * 20)


let a = new Student("a",1,1,1)
let b = new Student("b",1,1,1)
let c = new Student("c",1,1,1)

let students = [|a;b;c|] |> Array.sortByDescending(fun x -> x.getStudentAmount)

match students with
|_ when students.Length = 1 -> students.[0].Name
|_ when students.[0].getStudentAmount = students.[1].getStudentAmount -> "All"
|_ -> students.[0].Name

I couldn't get the syntax highlighting for F# so if anyone can point me in the right direction that would be much appreciated.

Collapse
 
jbristow profile image
Jon Bristow • Edited
    ```fsharp
    match students with
    |_ when students.Length = 1 -> students.[0].Name
    |_ when students.[0].getStudentAmount = students.[1].getStudentAmount -> "All"
    |_ -> students.[0].Name
    ```

renders as

    match students with
    |_ when students.Length = 1 -> students.[0].Name
    |_ when students.[0].getStudentAmount = students.[1].getStudentAmount -> "All"
    |_ -> students.[0].Name

(HEY, dev.to maintainers, this is one of those "won't fix bugs!" 😠 Why can't I nest backticks as in the github flavored markdown spec?)

Collapse
 
peterbunting profile image
Peter Bunting

Thank you