krasizorbov

Serialize String

Jul 19th, 2020
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution(input = []) {
  2.   let str = input.shift();
  3.   let result = {};
  4.   for (let i = 0; i < str.length; i++) {
  5.     if (!result.hasOwnProperty(str[i])) {
  6.       result[str[i]] = [];
  7.       result[str[i]].push(i);
  8.     } else {
  9.       result[str[i]].push(i);
  10.     }
  11.   }
  12.   for (const key in result) {
  13.     if (result.hasOwnProperty(key)) {
  14.       console.log(`${key}:${result[key].join("/")}`);
  15.     }
  16.   }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment