Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created June 20, 2017 06:51
Show Gist options
  • Save kyleshevlin/54d9d3653f7e7f5bb75a875cb57531b8 to your computer and use it in GitHub Desktop.
Save kyleshevlin/54d9d3653f7e7f5bb75a875cb57531b8 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/xerotos
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
"use strict";
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
function recursiveReverse(arr) {
if (arr.length === 0) {
return [];
} else {
var first = arr.shift();
return [].concat(_toConsumableArray(recursiveReverse(arr)), [first]);
}
}
var myArray = [1, 2, 3, 4, 5];
console.log(recursiveReverse(myArray));
</script>
<script id="jsbin-source-javascript" type="text/javascript">function recursiveReverse (arr) {
if (arr.length === 0) {
return []
} else {
const first = arr.shift()
return [ ...recursiveReverse(arr), first ]
}
}
const myArray = [1,2,3,4,5]
console.log(recursiveReverse(myArray))</script></body>
</html>
"use strict";
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
function recursiveReverse(arr) {
if (arr.length === 0) {
return [];
} else {
var first = arr.shift();
return [].concat(_toConsumableArray(recursiveReverse(arr)), [first]);
}
}
var myArray = [1, 2, 3, 4, 5];
console.log(recursiveReverse(myArray));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment