re: Daily Challenge #88 - Recursive Ninjas VIEW POST


F#, used an uint8 so you can't call chirp with an argument < 0.

module DailyChallenge

let chirp (n : uint8) : string =
    |> Seq.replicate (int n)
    |> String.concat "-"

This assumes that the . in the example belongs to the comment, not the actual chirp output. In case the . is necessary, the following step can be added at the end of the pipeline:

    |> sprintf "%s."


module DailyChallengeTests

open FsUnit.Xunit
open Xunit
open DailyChallenge

let ``single chirp``() = 
    chirp 1uy |> should equal "chirp"

let ``4 chirps``() = 
    chirp 4uy |> should equal "chirp-chirp-chirp-chirp"

let ``0 chirps``() = 
    chirp 0uy |> should equal ""
code of conduct - report abuse