getify / You-Dont-Know-JS

A book series on JavaScript. @YDKJS on twitter.
Other
178.28k stars 33.42k forks source link

modify: toggle example #1647

Closed albseb511 closed 4 years ago

albseb511 commented 4 years ago

Yes, I promise I've read the Contributions Guidelines (please feel free to remove this line).

Specifically quoting these guidelines regarding typos:

Typos?

Please don't worry about minor text typos. These will almost certainly be caught during the editing process.

If you're going to submit a PR for typo fixes, please be measured in doing so by collecting several small changes into a single PR (in separate commits). Or, just don't even worry about them for now, because we'll get to them later. I promise.


Please type "I already searched for this issue":

Edition: (pull requests not accepted for previous editions)

Book Title:

scope-closures

Chapter:

apB.md

Section Title:

Suggested Solutions

Topic:

Suggested: Closure (PART 2)

Modified the example for toggle. A bit more compact and uses arguments. I found it a bit more easier, as we are not doing any operations on the array like shift / unshift.

function toggle(){
    var i = 0
    var list = arguments
    return function(){
      if(i===list.length)
         i = 0
      return list[i++]    
    }
}
getify commented 4 years ago

I am glad you've found your own solution that you like better -- that means the book did its job in teaching you! -- but I'm not going to update the book with each person's own approaches. I just presented one suggested solution. Thanks.

albseb511 commented 4 years ago

Yeah that's fair enough. Just thought of making the example better.

Would it be valuable if I can contribute to different examples in the future? Rather than changing existing ones?

On Tue, 24 Mar 2020, 19:57 Kyle Simpson, notifications@github.com wrote:

I am glad you've found your own solution that you like better -- that means the book did its job in teaching you! -- but I'm not going to update the book with each person's own approaches. I just presented one suggested solution. Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/getify/You-Dont-Know-JS/pull/1647#issuecomment-603270481, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC4YPCYY2MNXE7UH3OVQZQDRJC7M5ANCNFSM4LSNHSXQ .

getify commented 4 years ago

Once I publish a book (like once it's complete) it's unlikely that I'll change the book just with alternate approach suggestions unless there are legitimate defects. This book was published about a month ago, so it's pretty unlikely anything more than minor fixes will occur.

While I'm writing a book here, suggestions are welcomed.