Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.somar = function () {
- function saoNumeros(item) {
- return typeof item === 'number';
- }
- function soma(anterior, atual) {
- return anterior + atual;
- }
- // Garante que todos os itens do Array
- // sejam números
- if (!this.every(saoNumeros)) return 0;
- return this.reduce(soma);
- };
- [1, 2, 3].somar(); // 6
- ['alcemar', 'illuminati', true].somar(); // 0
- Function.prototype.temArgumentos = function () {
- return this.length > 0;
- };
- false.toString.temArgumentos(); // false
- [].join.temArgumentos(); // true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement