Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function solve(input) {
  2. let dailyQuota = +input.shift();
  3. let finalPrize = 0;
  4. let fishesCounter = 0;
  5. let fishName = input.shift();
  6. while(fishName !== 'Stop') {
  7. if(fishName == 'Stop'){
  8. break;
  9. }
  10. let fishWeight = +input.shift();
  11. fishesCounter += 1;
  12. let fishNamePrize = 0;
  13. for(let j = 0; j < fishName.length; j++){
  14. let letterMoney = Number(fishName.charCodeAt(j));
  15. fishNamePrize += letterMoney;
  16. }
  17. let fishFullPrize = fishNamePrize / fishWeight;
  18. if(fishesCounter % 3 === 0) {
  19. finalPrize -= fishFullPrize;
  20. } else {
  21. finalPrize += fishFullPrize;
  22. }
  23. if(fishesCounter === dailyQuota) {
  24. console.log('Lyubo fulfilled the quota!');
  25. break;
  26. }
  27. fishName = input.shift();
  28. }
  29. if(finalPrize <= 0) {
  30. console.log(`Lyubo's profit from ${fishesCounter} fishes is ${Math.abs(finalPrize.toFixed(2))} leva.`)
  31. } else {
  32. console.log(`Lyubo lost ${finalPrize.toFixed(2)} leva today.`);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement