Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active April 29, 2021 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/8a7634377bfc78e14285d2cf6b588080 to your computer and use it in GitHub Desktop.
Save ORESoftware/8a7634377bfc78e14285d2cf6b588080 to your computer and use it in GitHub Desktop.
lacuna stuff
const list = ['a', 'b', 'c', 'c', 'd', 'a', 'b', 'a', 'a', 'd', 'b'];
const findMin = (char1: string, char2: string, arr: Array<string>) : Number => {
let char1Index = -1;
let char2Index = -1;
let min = Number.MAX_SAFE_INTEGER;
for (let i = 0; i < arr.length; i++) {
const el = arr[i];
if (String(arr[i])[0] === String(char1)[0]) {
if (char2Index >= 0 && (i - char2Index < min)) {
min = i - char2Index
}
char1Index = i
console.log({char1Index, i})
continue;
}
if (String(arr[i])[0] === String(char2)[0]) {
if (char1Index >= 0 && (i - char1Index < min)) {
min = i - char1Index
}
char2Index = i
console.log({char2Index, i})
continue;
}
}
return min;
};
console.log(
findMin('b','d',list)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment