amt

JS useful

amt
Jun 28th, 2021 (edited)
1,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ============
  2. // convert a number to linked lint in reverse
  3. f = n => n ? { val: n % 10, next: f(n / 10 | 0) } : null;
  4.  
  5. console.log( f(465) ); // { val: 5, next: { val: 6, next: { val: 4, next: null } } }
  6. ============
  7. function ReverseListNodeToArray(listNode) {
  8.         let returnedArray = []; // Initialise an array to return
  9.         if (listNode.next != null) { // ListNode has level?
  10.             // returnedArray = returnedArray.concat( // Merge with the node result
  11.             //     ReverseListNodeToArray(listNode.next)
  12.             // );
  13.           returnedArray = [...returnedArray, ...ReverseListNodeToArray(listNode.next)];
  14.         }
  15.         returnedArray.push(listNode.val); // Add current node's value
  16.         return returnedArray;
  17.     }
  18.  
  19. console.log( ReverseListNodeToArray(f(465) ));
  20. ============
  21. /* stylelint-disable at-rule-no-unknown */
  22. /* stylelint-disable color-named */
  23. /* stylelint-disable color-no-hex */
  24. /* stylelint-disable block-no-empty */
  25. /* stylelint-disable declaration-block-no-duplicate-properties */
  26. /* stylelint-disable declaration-block-no-shorthand-property-overrides */
  27. /* stylelint-disable declaration-no-important */
  28. /* stylelint-disable length-zero-no-unit */
  29. /* stylelint-disable no-descending-specificity */
  30. /* stylelint-disable no-duplicate-selectors */
  31. /* stylelint-disable order/declaration-block-properties-alphabetical-order */
  32. /* stylelint-disable property-no-vendor-prefix */
  33. /* stylelint-disable rule-empty-line-before */
  34. /* stylelint-disable selector-no-type */
  35. /* stylelint-disable selector-no-universal */
  36. /* stylelint-disable selector-pseudo-element-colon-notation */
  37. /* stylelint-disable shorthand-property-no-redundant-values */
  38. /* stylelint-disable value-list-comma-newline-after */
  39. ============
Add Comment
Please, Sign In to add comment