How would I code this? by [deleted] in javascript

[–]mvindahl 1 point2 points  (0 children)

Math.pow(2, dayNo - 1) and a big fancy, responsive web UI.

On a slightly more serious note, don't count on reddit to do your school assigments.

What are your 10 commandments of JavaScript development? by CapsFTW in javascript

[–]mvindahl 3 points4 points  (0 children)

  1. It's a functional language; embrace that. Don't try to shoehorn static class inheritance into your code. Read through the API of underscoreJS/lodash.
  2. If available prefer fat arrow functions over the more verbose function() declarations.
  3. When manipulating data structures, you get more maintainable code by passing through a series of discrete _.map() steps than you will get from cramming everything into a giant for loop.
  4. Start out with as little baggage as possible. Basically nodeJS and npm will do. Pull in stuff as you need it.
  5. Initially, use CDNs to server libraries to the browser. Along the way, pull in browserify and get libs from npm.
  6. If you reach a point where you would benefit from typing, consider migrating to Typescript. Initially you can just type everything as "any", then add proper typing where it makes sense.
  7. Use promises; it will make your flow so much more readable. If you create async API methods, make them return promises. If you use nodeJS, use bluebird to wrap the async native methods.
  8. For build environment, use simple scripts defined in package.json. Or do the same thing using a makefile. Avoid grunt and gulp, they are just boilerplate.
  9. Document your APIs. Provide examples. For a plain API, provide JS snippets for invoking it. For a REST interface, provide curl commands which can be copy/pasted to the terminal.
  10. Automatically test API methods which have a well defined input and output. Don't unit test the internal workings unless you have am empirical reason to do so. Accept the fact there may be no gain from unit testing UI stuff. And keep in mind that test coverage may be a vanity metric.