kstoyanov

js advance 10. Length Limit

Sep 14th, 2020 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Stringer {
  2.   constructor(string, length) {
  3.       this.innerString = string;
  4.       this.innerLength = Number(length);
  5.   }
  6.   increase(length) {
  7.       this.innerLength += length;
  8.   }
  9.   decrease(length) {
  10.       this.innerLength = Math.max(this.innerLength - length, 0);
  11.   }
  12.   toString() {
  13.       if (this.innerString.length > this.innerLength) {
  14.           return `${this.innerString.substring(0, this.innerLength)}...`;
  15.       } else if (this.innerString.length <= this.innerLength) {
  16.           return this.innerString;
  17.       } else {
  18.           return `...`;
  19.       }
  20.   }
  21. }
Add Comment
Please, Sign In to add comment