PPetkov2000

Favorite Movie

Nov 11th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(params) {
  2.   let command = params.shift();
  3.   let bestMovie = "";
  4.   let points = 0;
  5.   let bestPoints = 0;
  6.   let counter = 0;
  7.  
  8.   while (command !== "STOP") {
  9.     let movieTitle = command;
  10.     counter++;
  11.     points = 0;
  12.     for (let i = 0; i < movieTitle.length; i++) {
  13.       let letter = movieTitle[i];
  14.       let symbol = letter.charCodeAt(0);
  15.       points += symbol;
  16.  
  17.       if (letter === letter.toLowerCase()) {
  18.         points -= movieTitle.length * 2;
  19.       } else if (letter === letter.toUpperCase()) {
  20.         points -= movieTitle.length;
  21.       }
  22.     }
  23.  
  24.     if (points > bestPoints) {
  25.       bestPoints = points;
  26.       bestMovie = movieTitle;
  27.     }
  28.  
  29.     // Stopping the loop
  30.     if (counter === 7) {
  31.       console.log("The limit is reached.");
  32.       console.log(
  33.         `The best movie for you is ${bestMovie} with ${bestPoints} ASCII sum.`
  34.       );
  35.       break;
  36.     }
  37.     command = params.shift();
  38.   }
  39.  
  40.   if (command === "STOP") {
  41.     console.log(
  42.       `The best movie for you is ${bestMovie} with ${bestPoints} ASCII sum.`
  43.     );
  44.   }
  45. }
Add Comment
Please, Sign In to add comment