electronics shop hackerrank solution javascript
// electronics shop hackerrank solution javascript
function getMoneySpent(keyboards, drives, b) {
/*
* Write your code here.
*/
let sum = [];
let max = 0;
for(let i=0; i<keyboards.length; i++){
for(let j=0; j<drives.length; j++){
sum.push(keyboards[i] + drives[j]);
}
}
for(let k=0; k<sum.length; k++){
if(sum[k] <= b){
if(sum[k] > max){
max = sum[k];
}
}
}
if(max !== 0 && max <=b){
return max;
}else{
return -1;
}
}