Zhorzh

Untitled

Mar 10th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. let input = [
  2. '7 4',
  3. '1 5 4 7',
  4. ]
  5.  
  6. let print = this.print || console.log;
  7. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  8. const arr1 = gets().split(' ').map(Number);
  9. const arr2 = gets().split(' ').map(Number);
  10. const n = arr1[0];
  11. const k = arr2[1];
  12. class List {
  13. constructor() {
  14. this.items = []
  15. }
  16. add(item) {
  17. this.items.push(item);
  18. }
  19. get(index) {
  20. return this.items[index];
  21. }
  22. set(index, item) {
  23. return this.items[index] = item;
  24. }
  25. insert(index, item) {
  26. this.items.splice(index, 0, item);
  27. }
  28. remove(index) {
  29. this.items.splice(index, 1);
  30. }
  31. size() {
  32. return this.items.length;
  33. }
  34. values() {
  35. return [...this.items];
  36. }
  37. }
  38. let res = new List();
  39. for (let i = 1; i <= n; i++) {
  40. res.add(i);
  41. }
  42.  
  43. print(res.values());
Advertisement
Add Comment
Please, Sign In to add comment