阅读提示:
每个方法都有相应的描述、语法、参数、返回值、注意项(可选)、例子(可选)。
语法中的[]
里面中的内容表示参数为可选参数。
Array.from()
描述:从一个类似数组或可迭代对象中创建一个新的数组实例。
语法:
new_array = Array.from(arrayLike[, callback(element[, index[, array]])[, thisArg]]);
樊小书生的博客,多看代码,多看书,付出总会有收获的。
阅读提示:
每个方法都有相应的描述、语法、参数、返回值、注意项(可选)、例子(可选)。
语法中的[]
里面中的内容表示参数为可选参数。
Array.from()
描述:从一个类似数组或可迭代对象中创建一个新的数组实例。
语法:
new_array = Array.from(arrayLike[, callback(element[, index[, array]])[, thisArg]]);
by Pineapple (@Pineapple0919) #中等 #array
Implement the type version of Array.indexOf
, indexOf<T, U>
takes an Array T
, any U
and returns the index of the first U
in Array T
.
by Pineapple (@Pineapple0919) #中等 #array
Implement the type version of Array.join
, Join<T, U>
takes an Array T
, string or number U
and returns the Array T
with U
stitching up.
by Krzysztof "Wokay" Łokaj (@wokayme) #中等 #map #object #utils
Implement MapTypes<T, R>
which will transform types in object T to different types defined by type R which has the following structure
type StringToNumber = {
mapFrom: string; // value of key which value is string
mapTo: number; // will be transformed for number
}
by Lo (@LoTwT) #中等 #tuple
构造一个给定长度的元组。
例如
type result = ConstructTuple<2> // 期望得到 [unknown, unkonwn]
by AaronGuo (@HongxuanG) #中等
Sometimes we want to limit the range of numbers...
For examples.
type result = NumberRange<2 , 9> // | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
by Homyee King (@HomyeeKing) #中等 #array #application #string
Given an array of strings, do Permutation & Combination.
It's also useful for the prop types like video controlsList
by jiangshan (@jiangshanmeta) #中等 #tuple
Implement a type IsTuple
, which takes an input type T
and returns whether T
is tuple type.
For example:
type case1 = IsTuple<[number]> // true
type case2 = IsTuple<readonly [number]> // true
type case3 = IsTuple<number[]> // false
by キリサメ qianxi (@qianxi0410) #中等 #tuple
Do you know lodash
? Chunk
is a very useful function in it, now let's implement it.
Chunk<T, N>
accepts two required type parameters, the T
must be a tuple
, and the N
must be an integer >=1
by キリサメ qianxi (@qianxi0410) #中等 #tuple
Fill
, a common JavaScript function, now let us implement it with types.
Fill<T, N, Start?, End?>
, as you can see,Fill
accepts four types of parameters, of which T
and N
are required parameters, and Start
and End
are optional parameters.
The requirements for these parameters are: T
must be a tuple
, N
can be any type of value, Start
and End
must be integers greater than or equal to 0.