Skip to content

Instantly share code, notes, and snippets.

@franciscojsc
Created April 14, 2022 03:40
Show Gist options
  • Save franciscojsc/81937d7f6c740d3ec370dd9b2d53eeaa to your computer and use it in GitHub Desktop.
Save franciscojsc/81937d7f6c740d3ec370dd9b2d53eeaa to your computer and use it in GitHub Desktop.
Adicionando funções personalizadas ao objeto Array - JavaScript
Array.prototype.verifyEven = function () {
return this.filter((item) => {
if (item % 2 === 0) {
return item;
}
});
};
Array.prototype.verifyOdd = function () {
return this.filter((item) => {
if (item % 2 !== 0) {
return item;
}
});
};
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const evenNumbers = numbers.verifyEven();
const oddNumbers = numbers.verifyOdd();
console.log('Even numbers', evenNumbers);
console.log('Odd numbers', oddNumbers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment