implement Observable.from()
2022年5月1日小于 1 分钟
implement Observable.from()
Question
This is a follow-up on 57. create an Observable.
Suppose you have solved 57. create an Observable, here you are asked to implement a creation operator from()
.
From the document, from()
Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object.
Your from()
should accept all above types.
from([1,2,3]).subscribe(console.log);
// 1
// 2
// 3
Note
- Observable is already given for you, no need to create it.
- for the problem here,
Observable-like
meansObservable instance
. Though in real-world you should checkSymbol.observable
Code
/**
* @param {Array | ArrayLike | Promise | Iterable | Observable} input
* @return {Observable}
*/
function from(input) {
// your code here
}