First unique char index

Medium
union types
indexed types
conditional types
template literal
infer
recursion

Description:

Given a string S, find the first non-repeating character in it and return its index. If it does not exist, return -1.

For example:

type FirstUniqueCharIndex<'abcd'> // 0 type FirstUniqueCharIndex<'abaa'> // 1 type FirstUniqueCharIndex<'aabb'> // -1

Code

Loading...