2022-9-6

37 阅读1分钟

算法

  1. 使用双指针法,通过数学证明两个指针都走了a+b+c

ts体操

Tuple to Object

// ============= Test Cases =============
import type { Equal, Expect } from './test-utils'

const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const

type cases = [
  Expect<Equal<TupleToObject<typeof tuple>, { tesla: 'tesla'; 'model 3': 'model 3'; 'model X': 'model X'; 'model Y': 'model Y' }>>,
]


type error = TupleToObject<[[1, 2], {}]>


type TupleToObject<T extends readonly (string | number)[] >= {
  [k in T[number]]: k
}