09 2022 档案
摘要:Implement a type IsUnion, which takes an input type T and returns whether T resolves to a union type. For example: type case1 = IsUnion<string> // fal
阅读全文
摘要:Implement a type IsNever, which takes input type T. If the type of resolves to never, return true, otherwise false. For example: type A = IsNever<neve
阅读全文
摘要:TypeScript's string interpolation powers are incredible, especially since 4.1. Add some utilities from ts-toolbelt, and you've got a stew going. Here,
阅读全文
摘要:You can use subsciprtion.add(anotherSubscription)to combine subscriptions and cancel them at the same time. import { Observable } from 'rxjs'; const o
阅读全文
摘要:We want to convert export type Entity = | {type: "user"} | {type: "post"} | {type: "comment"} to type EntityWithId = | {type: "user", userId: string}
阅读全文
摘要:Implement Python liked any function in the type system. A type takes the Array and returns true if any element of the Array is true. If the Array is e
阅读全文
摘要:microtask -> requestAnimationFrame -> macrotask Each scheduler can just take callback as arguement asyncScheduler.schedule(() => console.log('async'))
阅读全文
摘要:Get an Object that is the difference between O & O1 /* _____________ Your Code Here _____________ */ type Diff<T, S> = { [K in Exclude<(keyof T | keyo
阅读全文
摘要:const fruitCounts = { apple: 12, banana: 23 } type PropUnion<T extends Record<PropertyKey, any>> = { [K in keyof T]: { [K2 in K]: T[K2] } }[keyof T] t
阅读全文
摘要:ShareReplay is using ReplaySubject. It will reply the messages to later subscribers. It turns unicast observable to multicase observable. shareReplay(
阅读全文
摘要:Store.js import { BehaviorSubject, Subject } from 'rxjs'; import { map, distinctUntilKeyChanged, scan } from 'rxjs/operators'; export class Observable
阅读全文
摘要:Replace the camelCase or PascalCase string with kebab-case. FooBarBaz -> foo-bar-baz For example type FooBarBaz = KebabCase<"FooBarBaz">; const foobar
阅读全文
摘要:Merge two types into a new type. Keys of the second type overrides keys of the first type. For example type foo = { name: string; age: string; } type
阅读全文
摘要:Implement the String to Union type. Type take string argument. The output should be a union of input letters For example type Test = '123'; type Resul
阅读全文
摘要:Implement the Absolute type. A type that take string, number or bigint. The output should be a positive number string For example type Test = -100; ty
阅读全文
摘要:Subject as resource can be shared amount multi observers. Normal Observable pattern is Cold observable, each subscription will get its own resource: i
阅读全文
摘要:In this challenge, you would need to write a type that takes an array and emitted the flatten array type. For example: type flatten = Flatten<[1, 2, [
阅读全文
摘要:Implement permutation type that transforms union types into the array that includes permutations of unions. type perm = Permutation<'A' | 'B' | 'C'>;
阅读全文
摘要:Write a function that takes in an array of unique integers and returns an array of all permutations of those integers in no particular order. If the i
阅读全文
摘要:Compute the length of a string literal, which behaves like String#length. /* _____________ Your Code Here _____________ */ type LengthOfString<S exten
阅读全文
摘要:If the server starts on a different port, such as 3001 or 3002, this is because another process is currently running on port 3000. This is ok, but you
阅读全文
摘要:For given function type Fn, and any type A (any in this context means we don't restrict the type, and I don't have in mind any type 😉) create a gener
阅读全文
摘要:Implement ReplaceAll<S, From, To> which replace the all the substring From with To in the given string S For example type replaced = ReplaceAll<'t y p
阅读全文
摘要:package main import ( "bufio" "fmt" "os" "strings" ) type name struct { fname []byte lname []byte } func main() { fmt.Print("File path ") var filename
阅读全文
摘要:Implement Replace<S, From, To> which replace the string From with To once in the given string S For example type replaced = Replace<'types are fun!',
阅读全文
摘要:Implement Capitalize<T> which converts the first letter of a string to uppercase and leave the rest as-is. For example type capitalized = Capitalize<'
阅读全文
摘要:ary := [...]int {1,2,3,4} // array sli := []int {1,2,3,4}// slice
阅读全文
摘要:The contenteditable global attribute is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies
阅读全文
摘要:Implement Trim<T> which takes an exact string type and returns a new string with the whitespace from both ends removed. For example type trimmed = Tri
阅读全文
摘要:Implement TrimLeft<T> which takes an exact string type and returns a new string with the whitespace beginning removed. For example type trimed = TrimL
阅读全文
摘要:Sometimes, you may want to lookup for a type in a union to by their attributes. In this challenge, we would like to get the corresponding type by sear
阅读全文
摘要:Type the function PromiseAll that accepts an array of PromiseLike objects, the returning value should be Promise<T> where T is the resolved result arr
阅读全文
摘要:TypeScript 4.0 is recommended in this challenge Implement a generic Pop<T> that takes an Array T and returns an Array without it's last element. For e
阅读全文
摘要:TypeScript 4.0 is recommended in this challenge Implement a generic Last<T> that takes an Array T and returns its last element. For example type arr1
阅读全文
摘要:Scan reads user input Takes a pointer as an argument Typed data is written to pointer Return number of scanned items var appleNum int fmt.Printf("Numb
阅读全文
摘要:iota Generate a set of related but distinct constants Often represents a property which has several distinct possible values Dyas of the week Months o
阅读全文
摘要:namespace AllGreetings { export namespace Greetings { export function returnGreeting (greeting: string) { console.log(`The message from namespace Gree
阅读全文
摘要:Chainable options are commonly used in Javascript. But when we switch to TypeScript, can you properly type it? In this challenge, you need to type an
阅读全文
摘要:Implement a generic TupleToUnion<T> which covers the values of a tuple to its values union. For example type Arr = ['1', '2', '3'] type Test = TupleTo
阅读全文
摘要:Implement a generic DeepReadonly<T> which make every parameter of an object - and its sub-objects recursively - readonly. You can assume that we are o
阅读全文
摘要:Implement a generic MyReadonly2<T, K> which takes two type argument T and K. K specify the set of properties of T that should set to Readonly. When K
阅读全文
摘要:Stack is dedicated to function Local variables are store in stack Deallocated after function completes Heap is persisten Carbage Collections Go is a c
阅读全文
摘要:New is alernate way to create a variable new() function create a variable and returns a pointer to the variable Variable is initialized to zero packag
阅读全文
摘要:Write a MinMaxStack class for a Min Max Stack. The class should support: Pushing and popping values on and off the stack. Peeking at the value at the
阅读全文
摘要:Implement the built-in Omit<T, K> generic without using it. Constructs a type by picking all properties from T and then removing K For example interfa
阅读全文
摘要:Implement the built-in ReturnType<T> generic without using it. For example const fn = (v: boolean) => { if (v) return 1 else return 2 } type a = MyRet
阅读全文
摘要:// User type User struct { ID int FirstName string } // Method func (u *User) describe() string { desc := fmt.Sprintf("Name %s", u.FirstName) return d
阅读全文
摘要:package main import ( "fmt" ) func recoverFromPanic() { fmt.Println("defer") } func doThings() { defer recoverFromPanic() for i := 0; i < 5; i++ { fmt
阅读全文
摘要:package main import ( "errors" "fmt" "strings" ) func shouldGreaterThanTen(num int) error { if num < 10 { return errors.New("Number is less than 10")
阅读全文
摘要:func changeName(name *string) { *name = strings.ToUpper(*name) } // Coordinates type Coordinates struct { X, Y float64 } func main() { name := "Elvis"
阅读全文
摘要:var name string var namePointer *string // Pointer name = "Beyonce" namePointer = &name // Assign a Pointer fmt.Println("Name: ", name) fmt.Println("N
阅读全文
摘要:package main import "fmt" type User struct { ID int FirstName string LastName string Email string } func main() { u := User{ID: 1, FirstName: "Z", Las
阅读全文
摘要:file: utils/math.go package utils import ( "fmt" ) func printNum(num int) { fmt.Println("Current number is: ", num) } // Add multi int number together
阅读全文
摘要:Create a new folder utilswith a new file math.go package utils import ( "fmt" ) func printNum(num int) { fmt.Println("Current number is: ", num) } //
阅读全文
摘要:A Go map type looks like this: map[KeyType]ValueType This variable m is a map of string keys to int values: var m map[string]int Map types are referen
阅读全文
摘要:An array has a fixed size. A slice, on the other hand, is a dynamically-sized, flexible view into the elements of an array. In practice, slices are mu
阅读全文
摘要:Slices can be created with the built-in make function; this is how you create dynamically sized arrays. The make function allocates a zeroed array and
阅读全文
摘要:package main import ( "fmt" ) func main() { //var scores [5]float64 //fmt.Println(scores) // [0.0, 0.0,0.0,0.0,0.0] //var scores [5]float64 = [5]float
阅读全文
摘要:Function can return multi values: func printAge(age int) (int, int) { return 12, age } func main() { age1, age2 := printAge(8) fmt.Println(age1) fmt.P
阅读全文
摘要:There is no While loop in Go, but you can use For loop as while loop: i := 1 for i < 100 { fmt.Println(i) i += 1 } func main() { var myTxt = "This is
阅读全文
摘要:fallthrough keyword is used in switch statement in golang. This keyword is used in switch case block. If the fallthrough keyword is present in the cas
阅读全文
摘要:// Defined a err variable err and assige the return value of someFunction() // err only available in if {} block, not outside if err := someFunction()
阅读全文
摘要:package main import ( "fmt" ) func main() { var firstName string = "firstName" var lastName = "lastName" var fullName string // Go will assign default
阅读全文
摘要:Can use reflect.TypeOf to get variable type package main import ( "fmt" "reflect" ) func main() { // var age int = 21 // var b bool = age >= 23 var ag
阅读全文
摘要:Implement the built-in Parameters generic without using it. For example: const foo = (arg1: string, arg2: number): void => {} type FunctionParamsType
阅读全文
摘要:Implement the type version of Array.unshift For example: type Result = Unshift<[1, 2], 0> // [0, 1, 2,] /* _____________ Your Code Here _____________
阅读全文
摘要:Implement the generic version of Array.push For example: type Result = Push<[1, 2], '3'> // [1, 2, '3'] /* _____________ Your Code Here _____________
阅读全文
摘要:Implement the Equal<T, U> For example: type isEqual = Equal<1, 1> // true Idea: Parameter type: <P>(x: P) => any Check P extends T ? 1: 2 Then check P
阅读全文
摘要:Creating a CLI in Node.js just takes a extra step or two because they are really just an ordinary Node.js app wrapped behind a bin command. For this e
阅读全文
摘要:Implement the JavaScript Array.includes function in the type system. A type takes the two arguments. The output should be a boolean true or false. For
阅读全文
摘要:Implement the JavaScript Array.concat function in the type system. A type takes the two arguments. The output should be a new array that includes inpu
阅读全文
摘要:Implement a utils If which accepts condition C, a truthy return type T, and a falsy return type F. C is expected to be either true or false while T an
阅读全文
摘要:If we have a type which is wrapped type like Promise. How we can get a type which is inside the wrapped type? For example: if we have Promise<ExampleT
阅读全文
摘要:Implement the built-in Exclude<T, U> For example: type Result = MyExclude<'a' | 'b' | 'c', 'a'> // 'b' | 'c' /* _____________ Your Code Here _________
阅读全文
摘要:For given a tuple, you need create a generic Length, pick the length of the tuple For example: type tesla = ['tesla', 'model 3', 'model X', 'model Y']
阅读全文
摘要:Implement a generic First<T> that takes an Array T and returns it's first element's type. type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1
阅读全文
摘要:If you cannot catch those pesky errors for any reason. Maybe some lib is throwing them and you can't catch them. You can use: process.on('uncaughtExce
阅读全文