-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement exercise 42 #108
Labels
Comments
Came here to report the same thing. |
some code for anyone that wants to write a lesson. The following is probably just a copy of lesson 42. <p>You'll notice in the previous exercise that if you pressed your arrow keys while inside the textbox, the query
- will still fire, regardless of whether the text actually changed or not. How do we prevent that? The
- distinctUntilChanged filters out successive repetitive values.</p>
- <pre>
- seq([1,,,1,,,3,,,3,,,5,,,1,,,]).distinctUntilChanged() ===
- seq([1,,,,,,,3,,,,,,,5,,,1,,,]);
- </pre>
-
- <textarea class="code" rows="60" cols="80">
- function (keyPresses, isAlpha) {
-
- return keyPresses.
- map(function (e) { return String.fromCharCode(e.keyCode); }).
-
- // Ensure we only have alphabetic characters
- filter(function (character) { return isAlpha(character); }).
-
- // TODO: Filter out successive repetitive keys
- // Building up a string of all the characters typed.
- scan('', function (stringSoFar, character) {
- return stringSoFar + character;
- });
- }
- </textarea>
-
- <button class="go">Run</button>
-
- <label for="inputName">Enter Keys</label>
- <input type="text" class="inputName">
-
- <div>Keys filtered by distinctUntilChanged</div>
- <div class="filteredKeysByDistinct"></div>
-
- <button class="showAnswer">Show Answer</button>
-
- <pre class="verifier">
- function(str, lesson) {
- preVerifierHook();
- var $inputName = $('.inputName', lesson),
- $filtered = $('.filteredKeysByDistinct', lesson);
-
- var keyups = Rx.Observable.fromEvent($inputName[0], 'keyup');
-
- var isAlpha = function (x) {
- return 'abcdefghijklmnopqrstuvwxyz'.indexOf(x.toLowerCase()) !== -1;
- };
-
- var code = eval("(" + str + ")")
- var code = code(keyups, isAlpha);
-
- code
- .subscribe(function (text) {
- $filtered.text(text);
- });
- }
- </pre>
- <pre class="answer">
- function (keyPresses, isAlpha) {
-
- return keyPresses.
- map(function (e) { return String.fromCharCode(e.keyCode); }).
- filter(function (character) { return isAlpha(character); }).
- distinctUntilChanged().
- scan('', function (stringSoFar, character) {
- return stringSoFar + character;
- });
- }
- </pre>
- <div class="post">
- <p>Now that we know how to get only the distinct input, let's see how it applies to our autocomplete example...</p>
-
- <h1>A Work in Progress</h1>
-
- <p>Congratulations! You've made it this far, but you're not done. Learning is an on-going process. Go out and start
- using the functions you've learned in your day-to-day coding. Over time, I'll be adding more exercises to this
- tutorial. If you have suggestions for more exercises, send me a pull request!
- </p>
- </div> |
morenoh149
changed the title
Exercise 42 is a copy of exercise 40
Implement exercise 42
Nov 30, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It says that exercise 42 is about learning how to retry after errors, but it's actually just a copy of the "Distinct Until Changed Input" exercise (40). Verified this was true in the index.html in this repo as well.
The text was updated successfully, but these errors were encountered: