javascript

Compressed String with Sort - C3 AI - CRM - Full Stack - 11/11/21

function compressedStr(input) {
  let compressedResult = input[0];
  let currentChar = input[0]
  let currentCount = 1
 
  for (let i = 1; i < input.length; i++) {
    if (currentChar == input[i]) {
      currentCount++;
    } else {
      compressedResult += currentCount;
      compressedResult += input[i];
 
      currentChar = input[i];
      currentCount = 1; 
    }
  }
 
  compressedResult += currentCount;
 
  return compressedResult;
}
 
console.log(compressedStr('aaaaaaaaaabbbbbjjjkklaa'));
 
function compressedSort(input) {
  let arr = []
  //[(a, 10), (b,5)] { char: 'a', count: '1'0 } 
  let currentChar = input[0];
  for (let i = 1; i < input.length; i++) {
    if (isCharacterALetter(input[i])) {
      
    } else {
      // Digit 
      
    }
  }
}
 
 
function isCharacterALetter(char) {
  return (/[a-zA-Z]/).test(char)
}
Was this helpful?