Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stringer {
- constructor(string, length) {
- this.innerString = string;
- this.innerLength = Number(length);
- }
- increase(length) {
- this.innerLength += length;
- }
- decrease(length) {
- this.innerLength = Math.max(this.innerLength - length, 0);
- }
- toString() {
- if (this.innerString.length > this.innerLength) {
- return `${this.innerString.substring(0, this.innerLength)}...`;
- } else if (this.innerString.length <= this.innerLength) {
- return this.innerString;
- } else {
- return `...`;
- }
- }
- }
Add Comment
Please, Sign In to add comment