javascript RxJS 中的排序数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33278225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:18:32  来源:igfitidea点击:

sort array in RxJS

javascriptreactive-programmingrx-javarxjs

提问by Giorgio

RxJava has a method toSortedList(Comparator comparator)that converts a flow of objects into a list of objects sorted by a Comparator.

RxJava 有一个方法toSortedList(Comparator comparator)可以将对象流转换为由 Comparator 排序的对象列表。

How can I achieve the same in JavaScript with RxJS and get an Observable with a flow of objects to emit a sorted array/list?

如何使用 RxJS 在 JavaScript 中实现相同的功能,并通过对象流获取 Observable 以发出已排序的数组/列表?

回答by VincentGuo

you can use the code following:

您可以使用以下代码:

Rx.Observable.of(5,8,7,9,1,0,6,6,5).toArray().map(arr=>arr.sort()).subscribe(x=>console.log(x))