supercharge / set Goto Github PK
View Code? Open in Web Editor NEWAn Array-aligned Set class and the one JavaScript should have shipped
Home Page: https://superchargejs.com/docs/set
License: MIT License
An Array-aligned Set class and the one JavaScript should have shipped
Home Page: https://superchargejs.com/docs/set
License: MIT License
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 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 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
Implement an any
method that returns true
if at least one item in the set matches a given predicate
function, otherwise false.
method-any
branch (contains tests)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
Implement a findLastIndex
method that returns the index of the last item in the set matching the given predicate
function. Returns -1
if no item matching the predicate was found in the set.
method-findLastIndex
branch (contains tests)Implement an intersect
method that returns a set containing all items that are contained in all collections, the given set and and all candidate sets
.
method-intersect
branch (contains tests)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 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
Implement an all
method that returns true
if all items in the set match a given predicate
function, otherwise false.
method-all
branch (contains tests)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.
method-findLast
branch (contains tests)A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.