Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
45
Task/Palindrome-detection/Elm/palindrome-detection.elm
Normal file
45
Task/Palindrome-detection/Elm/palindrome-detection.elm
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import String exposing (reverse, length)
|
||||
import Html exposing (Html, Attribute, text, div, input)
|
||||
import Html.Attributes exposing (placeholder, value, style)
|
||||
import Html.Events exposing (on, targetValue)
|
||||
import Html.App exposing (beginnerProgram)
|
||||
|
||||
-- The following function (copied from Haskell) satisfies the
|
||||
-- rosettacode task description.
|
||||
is_palindrome x = x == reverse x
|
||||
|
||||
-- The remainder of the code demonstrates the use of the function
|
||||
-- in a complete Elm program.
|
||||
main = beginnerProgram { model = "" , view = view , update = update }
|
||||
|
||||
update newStr oldStr = newStr
|
||||
|
||||
view : String -> Html String
|
||||
view candidate =
|
||||
div []
|
||||
([ input
|
||||
[ placeholder "Enter a string to check."
|
||||
, value candidate
|
||||
, on "input" targetValue
|
||||
, myStyle
|
||||
]
|
||||
[]
|
||||
] ++
|
||||
[ let testResult =
|
||||
is_palindrome candidate
|
||||
|
||||
statement =
|
||||
if testResult then "PALINDROME!" else "not a palindrome"
|
||||
|
||||
in div [ myStyle] [text statement]
|
||||
])
|
||||
|
||||
myStyle : Attribute msg
|
||||
myStyle =
|
||||
style
|
||||
[ ("width", "100%")
|
||||
, ("height", "20px")
|
||||
, ("padding", "5px 0 0 5px")
|
||||
, ("font-size", "1em")
|
||||
, ("text-align", "left")
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue