Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
487 B
2
Indexable
Never
function getMoneySpent(keyboards, drives, budget) {
    let underBudget = []

    for (let i = 0; i < keyboards.length; i++) {
        for (let j = 0; j < drives.length; j++) {
            let combo = keyboards[i] + drives[j]
            if (combo <= budget) {
                underBudget.push(combo);
                console.log(underBudget)
            }
        }
    }
    if (underBudget.length === 0) {
        return -1
    } else {
        return Math.max(...underBudget)
    }
}