Advertisement
elena1234

Closure (JavaScript) with Advanced Functions

Nov 28th, 2021
1,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.     let text = '';
  3.  
  4.     return {
  5.         append: x => text += x,
  6.         removeStart: n => text = text.slice(n),
  7.         removeEnd: n => text = text.substring(0, text.length - n),
  8.         print: () => console.log(text),
  9.     };
  10. }
  11.  
  12. let secondZeroTest = solution();
  13.  
  14. secondZeroTest.append('123');
  15. secondZeroTest.append('45');
  16. secondZeroTest.removeStart(2);
  17. secondZeroTest.removeEnd(1);
  18. secondZeroTest.print();
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement