Hello everyone, I recently started learning javascript and I'm facing a challenge with the following problem. Below is the code I've written so far and I would greatly appreciate any feedback on where I may be going wrong and how I can solve this issue, as well as guidance on handling the callback.
Question: Create a function called partition that takes in two parameters - an array of integer values and a callback function that returns a boolean. The function should iterate through the input array and based on the callback's return value, place the elements into either a left array or a right array.
const partition = function(arr, callback) {
let leftArr = [];
let rightArr = [];
for (let i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
leftArr.push(arr[i]);
} else {
rightArr.push(arr[i]);
}
}
return [leftArr, rightArr];
};