Skip to content
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

chapter10.md: some missing lines of codes #105

Open
Jemaz opened this issue Aug 11, 2017 · 7 comments
Open

chapter10.md: some missing lines of codes #105

Jemaz opened this issue Aug 11, 2017 · 7 comments

Comments

@Jemaz
Copy link

Jemaz commented Aug 11, 2017

At the "Splitting the program into functions", the particular code is written as:
// Get movies by Christopher Nolan const nolanMovies = () => { for (const movie of movieList) { if (movie.director === "Christopher Nolan") { nolanMovieList.push(movie); } } };

Where it should be:
// Get movies by Christopher Nolan const nolanMovies = () => { const nolanMovieList = []; for (const movie of movieList) { if (movie.director === "Christopher Nolan") { nolanMovieList.push(movie); } } return nolanMovieList; };

@Jemaz
Copy link
Author

Jemaz commented Aug 11, 2017

Excuse me for the bad formatting, still a newb to this.

@vsemozhetbyt
Copy link
Contributor

@Jemaz It seems this function uses the global variable that is declared below in that code fragment:

//...
const nolanMovieList = [];

console.log(titles());
// ...

@vsemozhetbyt
Copy link
Contributor

@Jemaz About formatting, you can read here:

https://help.github.com/articles/creating-and-highlighting-code-blocks/

Just use js or javascript label instead of ruby from the example in that help chapter)

@Jemaz
Copy link
Author

Jemaz commented Aug 12, 2017

@vsemozhetbyt Thanks truly for the formatting advice!
So there's a couple things wrong with it as I was doing the tutorial:

  1. The section is basically turning global vars into local vars by turning into functions (as I understood to eliminate any side-effects), the author did so except for the anonymous function "nolanMovies" which defeats the purpose of the exercise - which confused like a beginner like me
  2. It's missing a return statement

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Aug 12, 2017

@Jemaz I suppose both using the global variable and omitting the return are intended to show how a not pure function operates. It is a bit dizzying from the final point of view, but maybe this is the very sense of it)

@vsemozhetbyt
Copy link
Contributor

What was a bit more confusing for me: why the final byNolan() was not refactoring into the more generic byDirector(director). But this can also be intended to make the transition from the old code to the new one more smooth.

@bpesquet
Copy link
Collaborator

Thanks for your feedback. This chapter gave me a lot of headaches and is probably still too confusing. I leave this issue open in case someone else can provide good advice for improving it.

@bpesquet bpesquet reopened this Mar 28, 2018
kaypeter87 added a commit to kaypeter87/thejsway that referenced this issue Sep 10, 2019
* Update Chapter 18.

Very small changes to improve readability.

* Revamp README

* English screenshots of chap02 program

* Add link to launch article

* Fix typos chapter01.md

Small typo fixes on chapter01:
which -> whose
can not -> cannot

* Remove useless variable

* Update contributor list

* Added event listener to code example

The code example didn't have an event listener, so it just executed without the need of the button click. So I added the event listener.

* Add contributor

* grammar fix: "a URL"

I know it's minor, but URL as an abbreviation is pronounced as 'you-are-ell'. Y is a consonant, and the general rule is that 'an' is reserved for vowels, and 'a' is reserved for consonants.

* Update contributor list

* Fix thejsway#73

* Fix thejsway#104

* Fix thejsway#74

* (Try to) Fix thejsway#105

* Move environment setup chapter from appendices to intro

* Add Amazon to README

* Fix thejsway#130

* Typo fix

* Fixed a tiny, tiny typo

"request" was in source tags.

* Update copyright and add a contributor

* Update chapter24.md

Fix typo line 133

* Update contributor list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants