challenge-algorithms-Ana-Ca.../06-soma-dos-elementos/index.html

35 lines
993 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/*
Faça um algoritmo que retorne a soma de todos os numeros de um array
*/
function sum(numbers) {
// implementar logica aqui
let sumOfArrays = 0;
for(let index = 0; index < numbers.length; index +=1) {
sumOfArrays = sumOfArrays + numbers[index];
}
return sumOfArrays;
}
// Resultados esperados
console.log(sum([4,6,12,5]), 27) // 27
console.log(sum([9, 234, 312, 999, 21 , 2311]), 3886) // 3886
console.log(sum([533, 234, 23423, 32, 48876]), 73098 ) // 73098
console.log(sum([5, 4, 3, 2, 1]), 15 ) // 15
</script>
</body>
</html>