getMoneySpent.js

    0

    0

    The getMoneySpent() function will calculate the maximum amount of money that can be spent on keyboards, drives, and bulk batch. It will loop through each element of the arrays and calculate the total price of each item. If the total price of all three items is greater than the variable "b", the maximum value of each item will be set to "b".

    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;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.