plamen1982

asciiCombinations

Apr 1st, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. function asciiCombinations(args) {
  2. let n = Number(args[0]);
  3. let groupNumbers = 0
  4. let symbolNumbers = ''
  5.  
  6. let groupSmallLetters = 0
  7. let symbolSmallLetters = ''
  8.  
  9. let groupCapitalLetters = 0
  10. let symbolCapitalLetters = ''
  11.  
  12. let groupAllOthersSymbols = 0
  13. let symbolAllOthers = ''
  14.  
  15. let outputSymbols = ''
  16.  
  17. for(let i = 1; i <= n; i++) {
  18. if(args[i].charCodeAt() >= 48 && args[i].charCodeAt() <= 57) {
  19. groupNumbers += args[i].charCodeAt()
  20. symbolNumbers += args[i]
  21. } else if(args[i].charCodeAt() >= 97 && args[i].charCodeAt() <= 122) {
  22. groupSmallLetters += args[i].charCodeAt()
  23. symbolSmallLetters += args[i]
  24. }else if(args[i].charCodeAt() >= 65 && args[i].charCodeAt() <= 90) {
  25. groupCapitalLetters += args[i].charCodeAt()
  26. symbolCapitalLetters += args[i]
  27. }else {
  28. groupAllOthersSymbols += args[i].charCodeAt()
  29. symbolAllOthers += args[i]
  30. }
  31. }
  32. let arrayGroup = []
  33. arrayGroup.push(groupNumbers)
  34. arrayGroup.push(groupSmallLetters)
  35. arrayGroup.push(groupCapitalLetters)
  36. arrayGroup.push(groupAllOthersSymbols)
  37.  
  38. let max = Number.NEGATIVE_INFINITY;
  39.  
  40. for(let j = 0; j < arrayGroup.length; j++) {
  41. if(max < arrayGroup[j]) {
  42. max = arrayGroup[j]
  43. }
  44. }
  45. if(max == groupNumbers) {
  46. outputSymbols = symbolNumbers
  47. } else if(max == groupSmallLetters) {
  48. outputSymbols = symbolSmallLetters
  49. } else if(max == groupCapitalLetters) {
  50. outputSymbols = symbolCapitalLetters
  51. } else if(max == groupAllOthersSymbols) {
  52. outputSymbols = symbolAllOthers
  53. }
  54.  
  55. console.log(`Biggest ASCII sum is:${max}`)
  56. console.log(`Combination of characters is:${outputSymbols}`)
  57. }
  58.  
  59. asciiCombinations(["5", "9", "a", "V", "]", "7"])
Advertisement
Add Comment
Please, Sign In to add comment