Files
typescript-katas/6kyu/replace-with-alphabet-position/solution.ts
2025-01-31 23:05:40 +01:00

8 lines
295 B
TypeScript

export function alphabetPosition(text: string): string {
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
const indexArray = [...text]
.map((char) => alphabet.indexOf(char.toLowerCase()))
.filter((index) => index !== -1)
.map((index) => index + 1);
return indexArray.join(' ');
}