Sum of integers greater than or equal to 10 in an array

Given an array of integers, this function will return the sum of all integers that are greater than or equal to 10.

Problem

Given an array of integers, return the sum of the integers that are greater than or equal to 10.
Example input: [2, 12, 9, 15, 20]
Example output: 42

Solution

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

function sumOfTen(arr) {
  let sum = 0;
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] >= 10) {
      sum += arr[i];
    }
  }
  return sum;
}

// Explanation:
// This solution is optimal because it uses a for loop to iterate through the array and check if each element is greater than or equal to 10. If it is, it adds it to the sum. It then returns the sum.

A.I. Evaluation of the Solution

This is a great solution! It is very clear and easy to follow, and it efficiently solves the problem.

Evaluated at: 2022-11-19 08:16:40