montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

SortedSet error: "reverse is not a function" #183

Open axelpale opened 7 years ago

axelpale commented 7 years ago

I installed collections 5.0.6 via NPM today:

$ npm install --save collections

Then I tried to get a sorted set with the largest value first (smallest first by default) by calling reversed():

> var SortedSet = require('collections/sorted-set')
> var ss = new SortedSet([2, 8, 5, 3, 11])
> ss.toArray()
[ 2, 3, 5, 8, 11 ]
> var iss = ss.reversed()
TypeError: this.constructClone(...).reverse is not a function
    at SortedSet.GenericCollection.reversed (.../node_modules/collections/generic-collection.js:254:38)
    at repl:1:14
    at ContextifyScript.Script.runInThisContext (vm.js:23:33)
    at REPLServer.defaultEval (repl.js:339:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:101:20)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)

The docs claim SortedSet to have a reversed() method: http://www.collectionsjs.com/sorted-set http://www.collectionsjs.com/method/reversed

The docs also claim that reverse() (without d) method is only available for List: http://www.collectionsjs.com/method/reverse

What I was expecting was that reversed() would return another SortedSet with same contents but inverted sorting order.

nickyang07 commented 5 years ago

I also have this issue. Can this be fixed?

wittlesouth commented 5 years ago

See also #223. I probably should have looked at this first. This has been open since 2017?