daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Nov 11th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Sumator {
  2.   constructor() {
  3.     this.data = [];
  4.    
  5.     this.add(item) {
  6.         this.data.push(item);
  7.     }
  8.  
  9.     this.sumNums() {
  10.         let sum = 0;
  11.         for (let item of this.data)
  12.             if (typeof (item) === 'number')
  13.                 sum += item;
  14.         return sum;
  15.     }
  16.  
  17.     this.removeByFilter(filterFunc) {
  18.         this.data = this.data.filter(x => !filterFunc(x));
  19.     }
  20.    
  21.     this.toString() {
  22.         if (this.data.length > 0)
  23.             return this.data.join(", ");
  24.         else
  25.             return '(empty)';
  26.     }
  27.   }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top