Advertisement
PavelIvanov

Untitled

May 19th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. function solve(input) {
  2. let nameFilm = input.shift();
  3. let totalSum = 0;
  4. let isOver = false;
  5. let currentFilm = 0;
  6. let bestFilm ='';
  7. while (nameFilm != 'STOP') {
  8. let str = nameFilm.Length;
  9. for (i = 0; i < str; i++) {
  10. let counter = 0;
  11. counter++;
  12.  
  13. if (counter > 7) {
  14. isOver = true;
  15. break;
  16. }
  17.  
  18. let currentAscii = nameFilm.charCodeAt(i);
  19. if ((currentAscii >= 97) && (currentAscii <= 122)) {
  20. totalSum += (currentAscii - (str * 2));
  21. } else if ((currentAscii >= 65) && (currentAscii <= 96)) {
  22. totalSum += currentAscii - str;
  23. } else {
  24. totalSum += currentAscii;
  25. }
  26. }
  27.  
  28. if (currentFilm < totalSum) {
  29. currentFilm = totalSum;
  30. totalSum = 0;
  31. bestFilm=nameFilm;
  32.  
  33. }
  34.  
  35. nameFilm = input.shift();
  36. }
  37.  
  38. if(isOver){
  39. console.log(`The limit is reached.`);
  40. }
  41. console.log(`The best movie for you is ${bestFilm} with ${currentFilm} ASCII sum.`);
  42.  
  43.  
  44.  
  45. }
  46.  
  47. solve(
  48. ['Matrix', 'Breaking bad', 'Legend', 'STOP']
  49.  
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement