From 57946966fba6bceb8806cbc02990bfefce5e5655 Mon Sep 17 00:00:00 2001 From: Lance Wicks Date: Tue, 16 Feb 2021 22:39:44 +0000 Subject: Adding an (ugly) elm implementation --- challenge-100/lance-wicks/elm/elm.json | 28 ++++++++++ challenge-100/lance-wicks/elm/src/Fun.elm | 69 +++++++++++++++++++++++++ challenge-100/lance-wicks/elm/tests/Example.elm | 40 ++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 challenge-100/lance-wicks/elm/elm.json create mode 100644 challenge-100/lance-wicks/elm/src/Fun.elm create mode 100644 challenge-100/lance-wicks/elm/tests/Example.elm diff --git a/challenge-100/lance-wicks/elm/elm.json b/challenge-100/lance-wicks/elm/elm.json new file mode 100644 index 0000000000..7468f5e5cd --- /dev/null +++ b/challenge-100/lance-wicks/elm/elm.json @@ -0,0 +1,28 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "1.2.2" + }, + "indirect": { + "elm/random": "1.0.0" + } + } +} diff --git a/challenge-100/lance-wicks/elm/src/Fun.elm b/challenge-100/lance-wicks/elm/src/Fun.elm new file mode 100644 index 0000000000..2f9775c70b --- /dev/null +++ b/challenge-100/lance-wicks/elm/src/Fun.elm @@ -0,0 +1,69 @@ +module Fun exposing (convert) + + +convert : String -> String +convert time = + if String.contains "am" time then + String.slice 0 5 time + + else if String.contains "pm" time then + let + hourMin = + String.split ":" time + in + case List.head hourMin of + Just a -> + let + hour = + String.toInt a + in + case hour of + Just h -> + let + hx = + h + 12 + in + String.fromInt hx ++ String.slice 2 5 time + + Nothing -> + "" + + Nothing -> + "" + + else + let + hourMin = + String.split ":" time + in + case List.head hourMin of + Just a -> + let + hour = + String.toInt a + in + case hour of + Just h -> + if h > 12 then + let + hx = + h - 12 + in + let + hourStr = + String.fromInt hx + in + if String.length hourStr > 1 then + hourStr ++ String.slice 2 5 time ++ "pm" + + else + "0" ++ hourStr ++ String.slice 2 5 time ++ "pm" + + else + String.slice 0 5 time ++ "am" + + Nothing -> + "" + + Nothing -> + "" diff --git a/challenge-100/lance-wicks/elm/tests/Example.elm b/challenge-100/lance-wicks/elm/tests/Example.elm new file mode 100644 index 0000000000..64c70d1337 --- /dev/null +++ b/challenge-100/lance-wicks/elm/tests/Example.elm @@ -0,0 +1,40 @@ +module Example exposing (..) + +import Expect exposing (Expectation) +import Fun exposing (convert) +import Fuzz exposing (Fuzzer, int, list, string) +import Test exposing (..) + + +suite : Test +suite = + describe "Fun" + [ test "convert 07:15" <| + \_ -> + let + got = + convert "07:15" + in + Expect.equal got "07:15am" + , test "convert 05:15pm" <| + \_ -> + let + got = + convert "05:15 pm" + in + Expect.equal got "17:15" + , test "convert 19:15" <| + \_ -> + let + got = + convert "19:15" + in + Expect.equal got "07:15pm" + , test "convert 09:15" <| + \_ -> + let + got = + convert "09:15 am" + in + Expect.equal got "09:15" + ] -- cgit