Skip to content

Instantly share code, notes, and snippets.

@mckomo
Last active September 29, 2016 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckomo/b059372c034d73abe6bc97fb2c13059d to your computer and use it in GitHub Desktop.
Save mckomo/b059372c034d73abe6bc97fb2c13059d to your computer and use it in GitHub Desktop.
const list = ['m', 'c', 'k', 'o', 'm', 'o']
const reverse = (list) => {
if (list.length == 0) return [];
let first = list.splice(0, 1);
return reverse(list).concat(first);
}
let result = reverse(list);
console.log(result);
// [ 'o', 'm', 'o', 'k', 'c', 'm' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment