Created
April 14, 2022 03:40
-
-
Save franciscojsc/81937d7f6c740d3ec370dd9b2d53eeaa to your computer and use it in GitHub Desktop.
Adicionando funções personalizadas ao objeto Array - JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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