Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daubattu/7af670d58a6b2e00ca96a3762889820c to your computer and use it in GitHub Desktop.
Save daubattu/7af670d58a6b2e00ca96a3762889820c to your computer and use it in GitHub Desktop.
[Hackerrank] Solution of Electronics Shop in JavaScript
function getMoneySpent(keyboards, drives, b) {
/*
* Write your code here.
*/
let max = -1;
for(let i = 0; i < keyboards.length; i++) {
const keyboardPrice = keyboards[i];
for(let j = 0; j < drives.length; j++) {
const drivePrice = drives[j];
if (keyboardPrice + drivePrice <= b && keyboardPrice + drivePrice > max) {
max = keyboardPrice + drivePrice;
}
}
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment