Git Product home page Git Product logo

set's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

set's Issues

Add "first" method

Add a new .first(predicate?: (value: T, set: SuperchargedSet) method returns the first item in the set. If a predicate function is provided, return the first item found by predicate. When providing a predicate function, .first(predicate) is an alias for .find(predicate).

Example

Set.of([1, 2, 3]).first()
// 1

Set.of([1, 2, 3, 4, 5]).first(value => {
  return value > 3
})
// 4

Add "count" method

Add a new .count(predicate: T => boolean) method that returns the number of items matching the given predicate

Example

Set.of([1, 2, 3, 4, 5]).count(value => {
  return value > 3
})

// 2

Add "last" method

Add a new .last(predicate?: (value: T, set: SuperchargedSet) method returns the last item in the set. If a predicate function is provided, return the last item found by predicate.

Example

Set.of([1, 2, 3]).last()
// 3

Set.of([5, 4, 3, 2, 1]).last(value => {
  return value > 3
})
// 4

Add method: any

Implement an any method that returns true if at least one item in the set matches a given predicate function, otherwise false.

Requirements

Add "reduce" method

Add a new .reduce(operation, initialValue) method executes a reducer function on each item of the set, resulting in a single output value.

The method signature may look like this (Iโ€™m writing this freestyle, you may need to refine it when working in the code ๐Ÿ˜„ )

reduce<U>((operation: (previous: U, current: T, set: Set), initial: U): U`

Example

Set.of([1, 2, 3, 4]).reduce((sum, value) => {
  return sum + value
}, 0)

// 10

Add "concat" method

Add a new .concat(...values) method that appends the given values to the end of the set.

Example

Set.of([1, 2, 3]).concat([4, 5]).toArray()
// [1, 2, 3, 4, 5]

Set.of([1, 2, 3]).concat(4, 5).toArray()
// [1, 2, 3, 4, 5]

Add "includes" method

Add a new .includes(value: T | predicate: T => boolean) method that determines whether the set includes the given value or a value identified by the predicate function.

Returns true if the value is found in the collection or the predicate function returns an item from the collection. Returns false otherwise.

Example

Set.of([1, 2, 3, 4, 5]).includes(2)
// true

Set.of([1, 2, 3, 4, 5]).includes(value => {
  return value > 3
})
// true

Set.of([1, 2, 3, 4, 5]).includes(value => {
  return value === 0
})
// false

Add method: findLast

Implement a findLast method that returns the last item in the set matching the given predicate function. Returns undefined if no item matching the predicate was found in the set.

Requirements

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.