Last active
November 1, 2020 16:36
-
-
Save manzaloros/d0c8d3e170fedd7e459b12034d79136f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getDecimalValue = (head, [currentNode, string] = [head, '']) => { | |
do { | |
string += currentNode.val; | |
currentNode = currentNode.next; | |
} while (currentNode) | |
return parseInt(string, 2); | |
} | |
const getDecimalValue = (h, [c, a] = [h, []]) => { | |
do { | |
a.unshift(c.val); | |
c = c.next; | |
} while (c) | |
return a.reduce((d, n, i) => d += n * (!!n ? 2 ** i : 0), 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment