Sha256: 387e8ef48a8daaedbc140a87d050004a3ed8f45b17d7397079641257abb4ddeb

Contents?: true

Size: 452 Bytes

Versions: 132

Compression:

Stored size: 452 Bytes

Contents

interface Predicate<T> {
  (element: T): boolean
}

export function keep<T>(array: T[], predicate: Predicate<T>): T[] {
  const output: T[] = []
  array.forEach((el: T) => {
    if (predicate(el)) {
      output.push(el)
    }
  })
  return output
}

export function discard<T>(array: T[], predicate: Predicate<T>): T[] {
  const output: T[] = []
  array.forEach((el: T) => {
    if (!predicate(el)) {
      output.push(el)
    }
  })
  return output
}

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.179 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.178 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.177 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.176 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.175 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.174 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.173 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.172 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.171 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.170 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.169 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.167 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.166 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.165 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.164 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.163 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.162 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.161 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.160 tracks/typescript/exercises/strain/strain.example.ts