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 AskAI
SELECT SUM(CASE WHEN number % 2 = 0 THEN number ELSE 0 END) AS even_sum
FROM numbers;

/*

The above solution is optimal because it uses a CASE statement to check if the number is even and then returns the number if it is even and 0 if it is not.
The SUM function then adds up all the numbers in the column.

*/

A.I. Evaluation of the Solution

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.

Evaluated at: 2022-10-24 21:28:52

Community solutions:

Check these solutions from our community and artificial intelligence:
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.