Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let nameFilm = input.shift();
- let totalSum = 0;
- let isOver = false;
- let currentFilm = 0;
- let bestFilm ='';
- while (nameFilm != 'STOP') {
- let str = nameFilm.Length;
- for (i = 0; i < str; i++) {
- let counter = 0;
- counter++;
- if (counter > 7) {
- isOver = true;
- break;
- }
- let currentAscii = nameFilm.charCodeAt(i);
- if ((currentAscii >= 97) && (currentAscii <= 122)) {
- totalSum += (currentAscii - (str * 2));
- } else if ((currentAscii >= 65) && (currentAscii <= 96)) {
- totalSum += currentAscii - str;
- } else {
- totalSum += currentAscii;
- }
- }
- if (currentFilm < totalSum) {
- currentFilm = totalSum;
- totalSum = 0;
- bestFilm=nameFilm;
- }
- nameFilm = input.shift();
- }
- if(isOver){
- console.log(`The limit is reached.`);
- }
- console.log(`The best movie for you is ${bestFilm} with ${currentFilm} ASCII sum.`);
- }
- solve(
- ['Matrix', 'Breaking bad', 'Legend', 'STOP']
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement