Skip to content

Instantly share code, notes, and snippets.

@sauerlock
Last active October 25, 2022 14:24
Show Gist options
  • Save sauerlock/823b81c3ea5f2225ab0b66e0044e3110 to your computer and use it in GitHub Desktop.
Save sauerlock/823b81c3ea5f2225ab0b66e0044e3110 to your computer and use it in GitHub Desktop.
Exercicio 4 - Arrays
Exercicio 4 - Arrays
--------------------
A [Pen](https://codepen.io/sauerlock/pen/MWXWOmb) by [sauerlock](https://codepen.io/sauerlock) on [CodePen](https://codepen.io).
[License](https://codepen.io/license/pen/MWXWOmb).
// Crie uma função que receba um array de números retorne a soma dos primeiros 5 números ímpares desse array.
const numbers = [1, 3, 4, 5, 7, 8, 9, 11];
function numImpar(numbers) {
const numberSel = numbers.slice(0, 5);
const impar = numbers.filter((x) => x % 2 != 0);
for (var i = 0; i <= numbers.length; i++) {
return numberSel;
}
}
console.log(numImpar(numbers));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment