Sum of array elements

This problem asks the user to write a function that returns the sum of all integers in an array. An example input and output is provided.

Problem

Given an array of integers, write a function that returns the sum of the integers.
Example input:
[1, 2, 3, 4, 5]
Example output:
15

Solution

This solution is in JavaScript. Our A.I. can create solutions in multiple languages.
by kayakane
// Solution:

function sum(arr) {
  return arr.reduce((acc, curr) => acc + curr, 0);
}

// Explanation:
// The reduce method is the most optimal solution because it iterates through the array once and returns the sum of the integers.
// The reduce method is also the most readable solution.

A.I. Evaluation of the Solution

The candidate's solution is complete and solves the problem. The candidate's approach is clear and concise.

Evaluated at: 2022-11-22 12:16:44