I've been working on a JavaScript exercise and struggling to understand the logic behind it. The exercise involves a function named "mystery" that utilizes several basic functions to return an array in reversed order. Despite spending hours trying to decipher the code on a whiteboard, I can't seem to wrap my head around it. Could someone please help me understand how the mystery function accomplishes this? Your assistance would be greatly appreciated!
function rest(arr) {
return arr.slice(1);
}
function first(arr) {
return arr[0];
}
function conj(arr, value) {
arr.push(value);
return arr;
}
function mystery(array) {
if (array.length === 0) {
return [];
}
return conj(mystery(rest(array)), first(array));
}