Advertisement
pacho_the_python

Untitled

Jun 18th, 2023
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function theAngryCat(arrOfPrice, entryPoint, type) {
  2.     let leftSum = 0;
  3.     let rightSum = 0;
  4.     let entryEl = arrOfPrice[entryPoint];
  5.  
  6.     switch (type) {
  7.         case "cheap":
  8.             for (let l = 0; l < entryPoint; l++) {
  9.                 let currentLeft = arrOfPrice[l];
  10.                 if (currentLeft < entryEl) {
  11.                     leftSum += currentLeft;
  12.                 }
  13.             }
  14.             for (let j = entryPoint + 1; j < arrOfPrice.length; j++) {
  15.                 let currentRight = arrOfPrice[j];
  16.                 if (currentRight < entryEl) {
  17.                     rightSum += currentRight;
  18.                 }
  19.             }
  20.             break;
  21.         case "expensive":
  22.             for (let l = 0; l < entryPoint; l++) {
  23.                 let currentLeft = arrOfPrice[l];
  24.                 if (currentLeft >= entryEl) {
  25.                     leftSum += currentLeft;
  26.                 }
  27.             }
  28.             for (let j = entryPoint + 1; j < arrOfPrice.length; j++) {
  29.                 let currentRight = arrOfPrice[j];
  30.                 if (currentRight >= entryEl) {
  31.                     rightSum += currentRight;
  32.                 }
  33.             }
  34.             break;
  35.     }
  36.     if (rightSum > leftSum) {
  37.         console.log(`Right - ${rightSum}`);
  38.     } else {
  39.         console.log(`Left - ${leftSum}`);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement