mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
added <set>.replace(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e3992f3d0a
commit
ab470a9450
12
README.md
12
README.md
@ -38,6 +38,7 @@ Library of JavaScript type extensions, types and utilities.
|
||||
- [`Map`](#map)
|
||||
- [`<map>.sort(..)`](#mapsort)
|
||||
- [`Set`](#set)
|
||||
- [`<set>.replace(..)`](#setreplace)
|
||||
- [`<set>.unite(..)`](#setunite)
|
||||
- [`<set>.intersect(..)`](#setintersect)
|
||||
- [`<set>.subtract(..)`](#setsubtract)
|
||||
@ -887,6 +888,17 @@ require('ig-types/Set')
|
||||
```
|
||||
|
||||
|
||||
### `<set>.replace(..)`
|
||||
|
||||
Replace value in set with other value retaining item order
|
||||
```bnf
|
||||
<set>.replace(<old>, <new>)
|
||||
-> <union-set>
|
||||
```
|
||||
|
||||
Note that this might not be cheap for very large sets.
|
||||
|
||||
|
||||
### `<set>.unite(..)`
|
||||
|
||||
Unite two sets and return the resulting set
|
||||
|
||||
12
Set.js
12
Set.js
@ -45,6 +45,18 @@ object.Mixin('SetMixin', 'soft', {
|
||||
del(e)
|
||||
add(e) } }.bind(this))
|
||||
return this },
|
||||
|
||||
replace: function(old, value){
|
||||
// nothing to do...
|
||||
if(!this.has(old) || old === value){
|
||||
return this }
|
||||
var order = [...this]
|
||||
// XXX is this fast enough???
|
||||
order[order.lastIndexOf(old)] = value
|
||||
this.delete(old)
|
||||
this.add(value)
|
||||
this.sort(order)
|
||||
return this },
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-types",
|
||||
"version": "6.4.0",
|
||||
"version": "6.5.0",
|
||||
"description": "Generic JavaScript types and type extensions...",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user