Unshift
#
introductionImplement the type version of Array.unshift
For example
typescript
type Result = Unshift<[1, 2], 0>; // [0, 1, 2,]
View on GitHubtypescript
type Result = Unshift<[1, 2], 0>; // [0, 1, 2,]
#
start pointtsTry
/* _____________ Your Code Here _____________ */typeUnshift <T ,U > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Unshift <[], 1>, [1]>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Unshift <[1, 2], 0>, [0, 1, 2]>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Unshift <['1', 2, '3'], boolean>, [boolean, '1', 2, '3']>>];
take the challengetsTry
/* _____________ Your Code Here _____________ */typeUnshift <T ,U > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Unshift <[], 1>, [1]>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Unshift <[1, 2], 0>, [0, 1, 2]>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Unshift <['1', 2, '3'], boolean>, [boolean, '1', 2, '3']>>];