alboig

SignalFromSpace - JavascriptModule0

Apr 14th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Signal from Space
  2. // One day a signal from space was registered. Scientists managed to record the signal as a sequence of N symbols. It turned out that due to a technical difficulty some symbols have been repeated. Help the scientists by writing a program which removes consecutive repetitions of symbols, decoding the message.
  3.  
  4. // Input
  5. // Input data is read from the standard input
  6.  
  7. // On the only input line, a message is given
  8. // Output
  9. // Print to the standard output
  10.  
  11. // Print the decoded message
  12. // Constraints
  13. // The length of the message will be no more than 10000 symbols
  14. // Message consists of digits and Latin letters (upper and lower case)
  15. // Sample tests
  16. // Input
  17. // Hello
  18. // Output
  19. // Helo
  20. // Input
  21. // hoboobbo422222Aaao
  22. // Output
  23. // hobobo42Aao
  24. const input = ['Helloo'];
  25. const print = this.print || console.log;
  26. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  27. const initialSignalLength = gets();
  28. let translatedSignal = '';
  29. for (let i = 0; i < initialSignalLength.length; i++) {
  30.   if (initialSignalLength[i] !== initialSignalLength[i + 1]) {
  31.     translatedSignal += initialSignalLength[i];
  32.   } else {
  33.     continue;
  34.   }
  35. }
  36. print(translatedSignal);
Advertisement
Add Comment
Please, Sign In to add comment