Advertisement
Guest User

Untitled

a guest
May 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. // concat
  2. (() => {
  3. const x = [ 1, 2, 3 ];
  4. const y = [ 4, 5, 6 ];
  5. const o = x.concat(y);
  6. console.log(`concat: ${o}`);
  7. })();
  8.  
  9. // every
  10. (() => {
  11. const x = [ 1, 2, 3 ];
  12. const o = x.every((v) => v < 5);
  13. console.log(`every: ${o}`);
  14. })();
  15.  
  16. // some
  17. (() => {
  18. const x = [ 1, 2, 3 ];
  19. const o = x.some((v) => v <= 1);
  20. console.log(`some: ${o}`);
  21. })();
  22.  
  23. // filter
  24. (() => {
  25. const x = [ 1, 2, 5, 7 ];
  26. const o = x.filter((v) => v > 4);
  27. console.log(`filter: ${o}`);
  28. })();
  29.  
  30. // map
  31. (() => {
  32. const x = [ 1, 2, 3 ];
  33. const o = x.map((v) => v * v);
  34. console.log(`map: ${o}`);
  35. })();
  36.  
  37. // foreach
  38. (() => {
  39. const data = { entry: [ 'e1', 'e2', 'e3' ] };
  40. const x = [ 1, 2, 3 ];
  41.  
  42. let o = '';
  43. x.forEach(function (v, i) {
  44. o += `${i}-${v} ${this.entry[i]} `;
  45. }, data);
  46.  
  47. console.log(`forEach: ${o}`);
  48. })();
  49.  
  50. // indexOf
  51. (() => {
  52. const x = [ 1, 2, 3 ];
  53. const o1 = x.indexOf(2);
  54. const o2 = x.indexOf(5);
  55. console.log(`indexOf: ${o1}, ${o2}`);
  56. })();
  57.  
  58. // lastIndexOf
  59. (() => {
  60. const x = [ 1, 2, 3, 2 ];
  61. const o1 = x.lastIndexOf(2);
  62. const o2 = x.lastIndexOf(5);
  63. console.log(`lastIndexOf: ${o1}, ${o2}`);
  64. })();
  65.  
  66. // join
  67. (() => {
  68. const x = [ 1, 2, 3 ];
  69. const o = x.join('-')
  70. console.log(`join: ${o}`);
  71. })();
  72.  
  73. // push/pop
  74. (() => {
  75. const x = [ 1, 2, 3 ];
  76. const len1 = x.push(5);
  77. const out1 = [...x];
  78. const el = x.pop();
  79. const len2 = x.length;
  80. const out2 = [...x];
  81. console.log(`push/pop: ${len1}#${out1} | ${el} | ${len2}#${out2}`);
  82. })();
  83.  
  84. // unshift/shift
  85. (() => {
  86. const x = [ 1, 2, 3 ];
  87. const len1 = x.unshift(5);
  88. const out1 = Array.from(x);
  89. const el = x.shift();
  90. const len2 = x.length;
  91. const out2 = x.slice();
  92. console.log(`unshift/shift: ${len1}#${out1} | ${el} | ${len2}#${out2}`);
  93. })();
  94.  
  95. // reduce
  96. // reduceRight
  97.  
  98. // reverse
  99. (() => {
  100. const x = [ 1, 2, 3 ];
  101. const o = x.reverse();
  102. console.log(`reverse: ${o}`);
  103. })();
  104.  
  105. // sort
  106. (() => {
  107. // NOTE: in place sort
  108. const x = [ 7, 1, 2, 3 ];
  109. const out1 = Array.from(x.sort());
  110. const out2 = Array.from(x.sort((a, b) => b - a));
  111. console.log(`sort: ${out1} | ${out2}`);
  112. })();
  113.  
  114. // slice
  115. // splice
  116.  
  117. // toString
  118. (() => {
  119. // NOTE: in place sort
  120. const x = [ 7, 1, 2, 3 ];
  121. const o = x.toString();
  122. console.log(`toString: |${o}|`);
  123. })();
  124.  
  125. // find
  126. // findIndex
  127. // entries
  128. // from
  129. // keys
  130.  
  131. // [].copyWithin
  132. // [].fill
  133. // [].includes
  134. // [].values
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement