-
Code module AddNumbers where import Data.Monoid( Sum(..) ) add_arr :: [Int] -> Int add_arr = getSum . foldMap Sum
Test Cases module AddNumbersSpec where import Test.Hspec import AddNumbers spec :: Spec spec = do describe "add_arr" $ do it "1..9" $ do (add_arr [1..9]) `shouldBe` (45) it "1..3,-4,5..9" $ do (add_arr [1,2,3,-4,5,6,7,8,9]) `shouldBe` (37)
Output:
-
Code - module AddNumbers where
add_arr x = sum x- import Data.Monoid( Sum(..) )
- add_arr :: [Int] -> Int
- add_arr = getSum . foldMap Sum
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}