Hello, I recently attempted a code challenge but unfortunately only passed 9 out of the 16 tests. I am seeking feedback on what may be going wrong in my code. The problem link can be found here:
function getMoneySpent(keyboards, drives, budget) {
let comboArray = [];
let lenOfKeyboards = keyboards.length;
let lenOfDrives = drives.length;
let j = drives.length;
comboArray = keyboards.slice(0);
for (let number of drives) {
comboArray.push(number);
}
return (findMaxCombo(comboArray, lenOfKeyboards, budget));
}
function findMaxCombo(comboArray, lenOfKeyboards, budget) {
let result = [];
let j = lenOfKeyboards;
for (let i = 0; i < lenOfKeyboards; i++) {
if (comboArray[i] >= budget || comboArray[j] >= budget) return -1;
if (comboArray[i] + comboArray[j] < budget) {
result.push(comboArray[i] + comboArray[j]);
}
i--;
j++;
if (j == comboArray.length) {
i++;
j = lenOfKeyboards;
}
}
if (result.length == 0) return -1;
return result.sort()[result.length - 1];
}