### Daily Challenge #81 - Even or Odd

#### dev.to staff on October 02, 2019

Given a string of numbers confirm whether the total of all the individual even numbers are greater than the total of all the individual odd numbers...
[Read Full]

## Haskell

Since I'm not entirely sure what

a string of numbersmeans, I just assumed the function gets a list of integers.Could you explain what

`add (evens, odd)`

is (data type) and what does this piece do please?Sure! Let's start at

`partition`

, since we pass its output to`add`

. Partition takes a predicate function and returns a tuple`([Int], [Int])`

with the items of the list for which the predicate is true in the first position and the items for which the predicate is false in the second position. In this case, in the first position we'll have all the even numbers and in the second all the odd numbers, since we're using`even`

as predicate.Then

`add`

receives this tuple, which I destructure for convenience, and applies the function`sum`

to both elements, which sums all the items in each list.And the function signature for

`add`

would look like this.Lastly,

`answer`

takes the output of`add`

and checks the conditions in the guards (the`| <condition>`

thing) and returns the string for the first condition that matches or the string after`otherwise`

if none matches.Awesome, thanks for your answer! I didn't know the

`add`

function could take a tuple. Good to know!Elixir:

I read

`graphmemes`

instead of`graphemes`

, I should probably stop browsing the internet for today...Graph memes would be too... Edgy.

Sorry :)

RustRather than keeping two sums, we can negate one of the options (I chose to negate the evens) and compare the sum to 0:

Some JavaScript

ElmTestsGolangI assumed

string of numberswas an array.F#Tried to have a bit of fun with this one:

`map`

call for converting the strings to numbers, I used regular expressions for the partitioning.`tuple2Map`

for applying a function to both elements of a 2-tuple.Tests:

D version, assuming that the string of numbers is a string with integers separated by spaces:

Output:

A

Swiftsolution:c#, using linq, input validations omitted:

My solution in js

A Swift solution:

Outputs:

Went with accumulating by adding evens and subtracting odds so in a case where the list of values being summed up ends up greater than Int.max you don't get a runtime error...... not that these test cases are likely to total greater than 9223372036854775807.... haha

I just checked on Codewars the challenge, and the template for the JavaScript language is the following:

and the tests are

If it can help you understand a little bit more the challenge (yes, the instructions in this article were confusing).