Last active
August 29, 2015 13:57
-
-
Save CooperAtive/9544469 to your computer and use it in GitHub Desktop.
List Reversal
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
var list = | |
{ head: 1, | |
tail: { head: 2, | |
tail: { head: 3, | |
tail: { head: 4, | |
tail: { head: 5, | |
tail: null | |
} | |
} | |
} | |
} | |
}; | |
function listReverse(acc, list){ | |
if (list === null) return acc; | |
return listReverse({head: list.head, tail: acc}, list.tail); | |
} | |
console.log(JSON.stringify(listReverse(null, list))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment