INNER CODE UNIT · TypeScript
containsCharsInOrder
akirarika/milkio · packages/cookbook/src/index.ts:127
const containsCharsInOrder = (input: string, target: string): boolean => {
let inputIndex = 0;
for (const char of target) {
if (char === input[inputIndex]) {
inputIndex++;
if (inputIndex === input.length) break;
}
}
return inputIndex === input.length;
};
const calculateScore = (input: string, target: string) => {
let maxContiguous = 0;
let currentContiguous = 0;
let firstMatchIndex = -1;
let inputIndex = 0;
for (let i = 0; i < target.length; i++) {
if (target[i] === input[inputIndex]) {