Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. Array.prototype.somar = function () {
  2. function saoNumeros(item) {
  3. return typeof item === 'number';
  4. }
  5.  
  6. function soma(anterior, atual) {
  7. return anterior + atual;
  8. }
  9.  
  10. // Garante que todos os itens do Array
  11. // sejam números
  12. if (!this.every(saoNumeros)) return 0;
  13.  
  14. return this.reduce(soma);
  15. };
  16.  
  17. [1, 2, 3].somar(); // 6
  18. ['alcemar', 'illuminati', true].somar(); // 0
  19.  
  20. Function.prototype.temArgumentos = function () {
  21. return this.length > 0;
  22. };
  23.  
  24. false.toString.temArgumentos(); // false
  25. [].join.temArgumentos(); // true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement