Skip to content

Instantly share code, notes, and snippets.

@manzaloros
Last active November 1, 2020 16:36
Show Gist options
  • Save manzaloros/d0c8d3e170fedd7e459b12034d79136f to your computer and use it in GitHub Desktop.
Save manzaloros/d0c8d3e170fedd7e459b12034d79136f to your computer and use it in GitHub Desktop.
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