阅读提示:
每个方法都有相应的描述、语法、参数、返回值、注意项(可选)、例子(可选)。
语法中的[]
里面中的内容表示参数为可选参数。
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 ch3cknull (@ch3cknull) #中等 #array
In This Challenge, You should implement a type GreaterThan<T, U>
like T > U
Negative numbers do not need to be considered.
For example
GreaterThan<2, 1> //should be true
GreaterThan<1, 1> //should be false
GreaterThan<10, 100> //should be false
GreaterThan<111, 11> //should be true
by キリサメ qianxi (@qianxi0410) #中等 #tuple
In This Challenge, You should implement a type Zip<T, U>
, T and U must be Tuple
type exp = Zip<[1, 2], [true, false]> // expected to be [[1, true], [2, false]]
by jiangshan (@jiangshanmeta) #中等 #array
Implement the type version of Array.shift
For example
type Result = Shift<[3, 2, 1]> // [2, 1]
by jiangshan (@jiangshanmeta) #中等 #object #tuple
Given a tuple type T
that only contains string type, and a type U
, build an object recursively.
type a = TupleToNestedObject<['a'], string> // {a: string}
type b = TupleToNestedObject<['a', 'b'], number> // {a: {b: number}}
type c = TupleToNestedObject<[], boolean> // boolean. if the tuple is empty, just return the U type
by jiangshan (@jiangshanmeta) #中等 #tuple
实现类型版本的数组反转 Array.reverse
例如:
type a = Reverse<['a', 'b']> // ['b', 'a']
type b = Reverse<['a', 'b', 'c']> // ['c', 'b', 'a']
by jiangshan (@jiangshanmeta) #中等 #arguments
Implement the type version of lodash's _.flip
.
Type FlipArguments<T>
requires function type T
and returns a new function type which has the same return type of T but reversed parameters.
by jiangshan (@jiangshanmeta) #中等 #array
Recursively flatten array up to depth times.
For example:
type a = FlattenDepth<[1, 2, [3, 4], [[[5]]]], 2> // [1, 2, 3, 4, [5]]. flattern 2 times
type b = FlattenDepth<[1, 2, [3, 4], [[[5]]]]> // [1, 2, 3, 4, [[5]]]. Depth defaults to be 1
by Songhn (@songhn233) #中等 #template-literal #union #tuple
The Block, Element, Modifier methodology (BEM) is a popular naming convention for classes in CSS.
For example, the block component would be represented as btn
, element that depends upon the block would be represented as btn__price
, modifier that changes the style of the block would be represented as btn--big
or btn__price--warning
.
by Farhan Kathawala (@kathawala) #中等 #object
Implement the type of just-flip-object
. Examples:
Flip<{ a: "x", b: "y", c: "z" }>; // {x: 'a', y: 'b', z: 'c'}
Flip<{ a: 1, b: 2, c: 3 }>; // {1: 'a', 2: 'b', 3: 'c'}
Flip<{ a: false, b: true }>; // {false: 'a', true: 'b'}