We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3292e5b commit afed561Copy full SHA for afed561
reverse.js
@@ -0,0 +1,14 @@
1
+/**
2
+ *
3
+ * @param {Array} arr array of elements
4
+ * @returns {Array} a new array with the elements in the inverse order
5
+ */
6
+ function reverse(arr) {
7
+ if (arr.length === 0) return []
8
+ const x = arr[0]
9
+ const xs = arr.slice(1)
10
+ return reverse(xs).concat([x])
11
+}
12
+
13
+console.log(reverse([1,2,3]))
14
+console.log(reverse([]))
0 commit comments