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.119 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.118 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.117 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.116 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.115 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.114 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.113 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.111 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.110 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.109 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.108 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.107 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.106 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.105 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.104 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.103 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.102 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.101 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.100 tracks/typescript/exercises/strain/strain.example.ts
trackler-2.2.1.99 tracks/typescript/exercises/strain/strain.example.ts