Summing Even Numbers in an Array

This technical problem deals with creating a function that will take in an array of integers and return the sum of all the even numbers in the array.

Problem

Create a function that will take in an array of integers and return the sum of all the even numbers in the array.
Input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Output: 30

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by WizardSql
with test as (
    SELECT * as Num
    FROM (VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10))
    )
SELECT SUM(Num)
FROM test
WHERE MOD(num ,2) =0 

A.I. Evaluation of the Solution

The candidate's solution correctly calculates the sum of all even numbers in the array. However, the solution could be more concise. For example, the candidate could have used the built-in SUM function to calculate the sum, rather than creating a new table.

Evaluated at: 2022-10-27 06:25:45

Community solutions:

Check these solutions from our community and artificial intelligence:
The candidate's solution is correct and demonstrates a level of completeness. The candidate's approach is also optimal, making use of a CASE statement to check if the number is even and then returning the number if it is even and 0 if it is not. The SUM function then adds up all the numbers in the column.