Advertisement
ListonFermi

Week 20 | Reviewer: Muhammed Riyas

Apr 29th, 2024
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | Source Code | 0 0
  1. // const k = 10;
  2.  
  3. // switch (true) {
  4. // case k > 1 && k < 2:
  5. // console.log(k);
  6. // break;
  7. // case k == 10:
  8. // console.log("k==10");
  9. // break;
  10. // }
  11.  
  12. // function Hello() {
  13. // this.a = 10;
  14. // }
  15.  
  16. // // ?. ??
  17.  
  18. // console.log(a.filter((v) => v % 2 === 0).sort((a, b) => b - a)[1]);
  19.  
  20. // // a.reduce((acc,curr)=>{
  21. // // if(curr%2==0 ) return acc
  22. // // },0)
  23.  
  24. // function SL(a) {
  25. // let SL = -Infinity,
  26. // L = -Infinity;
  27. // a= a.filter((v) => v % 2 === 0)
  28. // for (let val of a) {
  29. // if (val > SL && val < L) SL = val;
  30. // else if (val > L) {
  31. // SL = L;
  32. // L = val;
  33. // }
  34. // }
  35. // return SL
  36. // }
  37.  
  38. // const a = [-2,-4,-8];
  39. // console.log(SL(a));
  40.  
  41. // function* hello(){
  42. // yield 1;
  43. // yield 2;
  44. // }
  45.  
  46. // const h1= hello()
  47.  
  48. // console.log(h1.next().value)
  49.  
  50. // // const
  51.  
  52. // function hello(a,b){
  53. // return hello2(c){
  54.  
  55. // }
  56. // }
  57.  
  58. // hello(1,2)(3)
  59.  
  60. // h1.addEventListener('click',()=>,true )
  61.  
  62. // db.createCollection('')
  63.  
  64. //
  65.  
  66. class Node {
  67. constructor(val) {
  68. this.val = val;
  69. this.next = null;
  70. }
  71. }
  72.  
  73. class LinkedList {
  74. constructor() {
  75. this.head = null;
  76. this.tail = null;
  77. }
  78.  
  79. prepend(val) {
  80. const node = new Node(val);
  81.  
  82. if (this.head) {
  83. node.next = this.head;
  84. } else {
  85. this.tail = node;
  86. }
  87. this.head = node;
  88. }
  89. //10,20,30
  90. revRecursive(curr = this.head, res = []) {
  91. if (!curr) return res.reverse();
  92.  
  93. res.push(curr.val); //10 //10,20,30
  94. return this.revRecursive(curr.next, res);
  95. }
  96. }
  97.  
  98. const list = new LinkedList();
  99. list.prepend(10);
  100. list.prepend(20);
  101. list.prepend(30);
  102. //30,20,10
  103. console.log(list.head)
  104. console.log(list.revRecursive());
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement