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?
Similar Posts
- 2D Array Path - C3 AI - CRM - Full Stack - 11/11/21
- Valid Dictonary String - Bloomberg - Port Interactive Analytics - Full Stack - 11/8/21
- Sort array using Array.sort() in javascript
- Van Ecks Sequence - Bloomberg - Asset Management AIM - Full Stack - 11/5/21
- Recommendations - Bloomberg - Port Interactive Analytics - Full Stack - 11/8/21
- Difference in Gift Values - Free Will - Nonprofit Gifts - Full Stack - 11/15/21
- Name Matching - Checkr - Adjudication - Full Stack - 11/19/21