Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions modulo6/resolvendo-problemas/1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function isOneEdit(strA: string, strB: string): boolean {
if (Math.abs(strB.length - strA.length) > 1) return false

if (strA.length > strB.length) return strA.includes(strB)
if (strB.length > strA.length) return strB.includes(strA)

let charsDiffCount = 0
for (let i = 0; i < strA.length; i++) {
if (strA[i] !== strB[i]) charsDiffCount++
}

return charsDiffCount === 1
}
22 changes: 22 additions & 0 deletions modulo6/resolvendo-problemas/2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const stringCompression = (input) => {
const substrings = [];
let lastChar = input[0];
let charCount = 0;

for (const char of input) {
if (char !== lastChar) {
substrings.push(lastChar + charCount);
lastChar = char;
charCount = 0;
}
charCount++;
}

substrings.push(lastChar + charCount);
let result = "";
for (const key of substrings) {
result += key;
}

return result.length > input.length ? input : result;
};