Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Co-authored-by: Muhun Kim <5278201+x86chi@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mu-hun authored Nov 16, 2022
1 parent 80ca6a0 commit 2044c75
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions questions/18220-medium-filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement the type `Filter<T, Predicate>` takes an Array `T`, primitive type or union primitive type `Predicate` and returns an Array include the elements of `Predicate`.
7 changes: 7 additions & 0 deletions questions/18220-medium-filter/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
difficulty: medium
title: Filter
tags: array, filter
author:
github: x86chi
name: Muhun Kim

5 changes: 5 additions & 0 deletions questions/18220-medium-filter/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type a = Filter<[0, 1, 2], 2> // expected to be [2]
type b = Filter<[0, 1, 2], 0 | 1> // expected to be [0, 1]

type Falsy = false | 0 | '' | null | undefined
type c = Filter<[0, 1, 2], Falsy> // expected to be [0]
10 changes: 10 additions & 0 deletions questions/18220-medium-filter/test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Equal, Expect } from '@type-challenges/utils'
import { ExpectFalse, NotEqual } from '@type-challenges/utils'

type Falsy = false | 0 | '' | null | undefined

type cases = [
Expect<Equal<Filter<[0, 1, 2], 2>, [2]>>
Expect<Equal<Filter<[0, 1, 2], 0 | 1>, [0, 1]>>
Expect<Equal<Filter<[0, 1, 2], Falsy>, [0]>>
]

0 comments on commit 2044c75

Please sign in to comment.