Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ============
- // convert a number to linked lint in reverse
- f = n => n ? { val: n % 10, next: f(n / 10 | 0) } : null;
- console.log( f(465) ); // { val: 5, next: { val: 6, next: { val: 4, next: null } } }
- ============
- function ReverseListNodeToArray(listNode) {
- let returnedArray = []; // Initialise an array to return
- if (listNode.next != null) { // ListNode has level?
- // returnedArray = returnedArray.concat( // Merge with the node result
- // ReverseListNodeToArray(listNode.next)
- // );
- returnedArray = [...returnedArray, ...ReverseListNodeToArray(listNode.next)];
- }
- returnedArray.push(listNode.val); // Add current node's value
- return returnedArray;
- }
- console.log( ReverseListNodeToArray(f(465) ));
- ============
- /* stylelint-disable at-rule-no-unknown */
- /* stylelint-disable color-named */
- /* stylelint-disable color-no-hex */
- /* stylelint-disable block-no-empty */
- /* stylelint-disable declaration-block-no-duplicate-properties */
- /* stylelint-disable declaration-block-no-shorthand-property-overrides */
- /* stylelint-disable declaration-no-important */
- /* stylelint-disable length-zero-no-unit */
- /* stylelint-disable no-descending-specificity */
- /* stylelint-disable no-duplicate-selectors */
- /* stylelint-disable order/declaration-block-properties-alphabetical-order */
- /* stylelint-disable property-no-vendor-prefix */
- /* stylelint-disable rule-empty-line-before */
- /* stylelint-disable selector-no-type */
- /* stylelint-disable selector-no-universal */
- /* stylelint-disable selector-pseudo-element-colon-notation */
- /* stylelint-disable shorthand-property-no-redundant-values */
- /* stylelint-disable value-list-comma-newline-after */
- ============
Add Comment
Please, Sign In to add comment