electricessence / TypeScript.NET

A JavaScript-Friendly .NET Based TypeScript Library (Moved)
https://github.com/electricessence/TypeScript.NET-Core
Other
251 stars 36 forks source link

Unable to use sort on a list #63

Closed Ralf71 closed 7 years ago

Ralf71 commented 7 years ago

I am not sure if this feature is supposed to be there at all, but asking anyway: Is there a way to issue a list.sort() ? I cannot find it.

I found a sort on array types, is that the way to go?

Thanks!

electricessence commented 7 years ago

Ok so you bring up an interesting point if you are referring to List<T>. All the collections contained here inherit from CollectionBase<T> to provide the majority of the method implementations and abstracts for ICollection<T>.

I did not implement a sort method on List<T> (yet) because there are a variety of sort implementations. One option is to simply:

let a = list.toArray();
a.sort();

You can also use LINQ and .orderBy() as another way of sorting.

Now keep in mind that arrays in JavaScript are the analog of List<T> for the most part. And List<T> is simply a API wrapper for an array.

I'll look into adding the sort methods.

electricessence commented 7 years ago

https://github.com/electricessence/TypeScript.NET/commit/02cea00c320f437b6e8a91c1863d435c8d9f09d7 This simply allows for publicly calling sort on the underlying array and by the same pattern returns this (the list that was sorted) but doesn't expose the underlying array directly.