Skip to content

Instantly share code, notes, and snippets.

View sergzak022's full-sized avatar

Zakharchenko Sergey sergzak022

  • Shoutpoint
View GitHub Profile
@sergzak022
sergzak022 / zip-strings.js
Created March 16, 2018 17:16
Recursive implementation for zipStrings function
function zipStrings(str1, str2) {
if (str1[0] == null && str2[0] == null) {
return '';
}
let ch1 = str1[0];
let ch2 = str2[0];
let tail = zip(
@sergzak022
sergzak022 / ex7. RxJS: Switching and Exhausting.js
Created January 18, 2018 21:42
RxJS: Switching and Exhausting
var exhausted$ = source$.exhaustMap((number) => {
return multBy2Delayed(number);
});
// Code above will work exactly the same as code bellow
var exhausted$ = source$.map((number) => {
return multBy2Delayed(number);
}).exhaust();
@sergzak022
sergzak022 / ex6. RxJS: Switching and Exhausting.js
Created January 18, 2018 21:41
RxJS: Switching and Exhausting
var switched$ = source$.map((number) => {
return multBy2Delayed(number);
}).switch();
// Code above will work exactly the same as code bellow
var switched$ = source$.switchMap((number) => {
return multBy2Delayed(number);
});
@sergzak022
sergzak022 / ex5. RxJS: Switching and Exhausting.js
Created January 18, 2018 21:41
RxJS: Switching and Exhausting
var source$ = Observable.timer(0, 200).take(6);
function multBy2Delayed(number) {
// I take 1000ms to multiply your number by two
return Observable.timer(1000).map(() => number * 2);
}
// NEW CODE STARTS HERE
var exhausted$ = source$.exhaustMap((number) => {
@sergzak022
sergzak022 / ex4. RxJS: Switching and Exhausting.js
Created January 18, 2018 21:40
RxJS: Switching and Exhausting
var source$ = Observable.timer(0, 200).take(6);
function multBy2Delayed(number) {
// I take 1000ms to multiply your number by two
return Observable.timer(1000).map(() => number * 2);
}
// NEW CODE STARTS HERE
var switched$ = source$.switchMap((number) => {
@sergzak022
sergzak022 / ex3. RxJS: Switching and Exhausting.js
Created January 18, 2018 21:39
RxJS: Switching and Exhausting
function multBy2Delayed(number) {
// I take 1000ms to multiply your number by two
return Observable.timer(1000).map(() => number * 2);
}
@sergzak022
sergzak022 / ex2. RxJS: Switching and Exhausting.js
Last active January 18, 2018 21:37
RxJS: Switching and Exhausting
// will log 0,1,2,3,4,5 to console
Observable.timer(0, 200).take(6).subscribe((val) => console.log(val));
@sergzak022
sergzak022 / ex1. RxJS: Switching and Exhausting.js
Last active January 18, 2018 21:38
RxJS: Switching and Exhausting
var source$ = Observable.timer(0, 200).take(6);