mirror of
https://github.com/flynx/types.js.git
synced 2025-10-29 02:20:07 +00:00
added a unorderd option to <set>.replace(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ab470a9450
commit
31c0755124
@ -893,10 +893,15 @@ require('ig-types/Set')
|
||||
Replace value in set with other value retaining item order
|
||||
```bnf
|
||||
<set>.replace(<old>, <new>)
|
||||
-> <union-set>
|
||||
-> <set>
|
||||
```
|
||||
|
||||
Note that this might not be cheap for very large sets.
|
||||
This might not be cheap for very large sets, to simply replace
|
||||
the value without sorting use:
|
||||
```bnf
|
||||
<set>.replace(<old>, <new>, false)
|
||||
-> <set>
|
||||
```
|
||||
|
||||
|
||||
### `<set>.unite(..)`
|
||||
|
||||
14
Set.js
14
Set.js
@ -46,16 +46,20 @@ object.Mixin('SetMixin', 'soft', {
|
||||
add(e) } }.bind(this))
|
||||
return this },
|
||||
|
||||
replace: function(old, value){
|
||||
replace: function(old, value, ordered=true){
|
||||
// nothing to do...
|
||||
if(!this.has(old) || old === value){
|
||||
return this }
|
||||
var order = [...this]
|
||||
// XXX is this fast enough???
|
||||
order[order.lastIndexOf(old)] = value
|
||||
if(ordered){
|
||||
var order = [...this]
|
||||
// XXX is this fast enough???
|
||||
order[order.lastIndexOf(old)] = value }
|
||||
|
||||
this.delete(old)
|
||||
this.add(value)
|
||||
this.sort(order)
|
||||
|
||||
ordered
|
||||
&& this.sort(order)
|
||||
return this },
|
||||
})
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-types",
|
||||
"version": "6.5.0",
|
||||
"version": "6.5.1",
|
||||
"description": "Generic JavaScript types and type extensions...",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user