From 6b194b8a305de7b1ce603983129f2bad60431c9a Mon Sep 17 00:00:00 2001 From: Uma Chandran Date: Mon, 26 Mar 2018 15:39:10 -0400 Subject: [PATCH] adds example solutions for the observables homework --- observables/exercise-1/observables.js | 4 +++- observables/exercise-2/observables.js | 4 +++- observables/exercise-3/observables.js | 5 +++++ observables/exercise-4/observables.js | 4 ++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/observables/exercise-1/observables.js b/observables/exercise-1/observables.js index 10af848..a86a6b9 100644 --- a/observables/exercise-1/observables.js +++ b/observables/exercise-1/observables.js @@ -7,4 +7,6 @@ const clickStream = Observable.fromEvent(theButton, "click"); Exercise 1: We've created an Observable stream from the button's click event above. Subscribe to the stream and print out the emitted value. -*/ \ No newline at end of file +*/ + +clickStream.subscribe(value => console.log('click event: ', value)); diff --git a/observables/exercise-2/observables.js b/observables/exercise-2/observables.js index 9f29504..dbb121c 100644 --- a/observables/exercise-2/observables.js +++ b/observables/exercise-2/observables.js @@ -13,4 +13,6 @@ const clickStream = Observable.fromEvent(theButton, "click"); "Dog #1" after the first click, "Dog #2" after the second, and so on. */ - +clickStream + .map((value, index) => `Dog #${index + 1}`) + .subscribe(dog => console.log(dog)); diff --git a/observables/exercise-3/observables.js b/observables/exercise-3/observables.js index 08e6feb..8af1273 100644 --- a/observables/exercise-3/observables.js +++ b/observables/exercise-3/observables.js @@ -17,3 +17,8 @@ const clickStream = Observable.fromEvent(theButton, "click"); No output after the fourth click, "Dog #5" after the fith click, and so on. */ + +clickStream + .map((value, index) => `Dog #${index + 1}`) + .filter((value, index) => index % 2 === 0) + .subscribe(dog => console.log(dog)); diff --git a/observables/exercise-4/observables.js b/observables/exercise-4/observables.js index d8706a4..8aaa351 100644 --- a/observables/exercise-4/observables.js +++ b/observables/exercise-4/observables.js @@ -19,3 +19,7 @@ const clickStream = Observable.fromEvent(theButton, "click"); If you click the button extra times before each 1000ms is up, we shouldn't see a generated dog. */ +clickStream + .throttleTime(1000) + .map((value, index) => `Dog #${index + 1}`) + .subscribe(dog => console.log(dog)); \ No newline at end of file