Reading Class 9 - Ginsusamurai/seattle-301d58 GitHub Wiki

concepts of functional programming

  • functional programming - building around the evaluation of mathematical functions and avoiding changing-state and mutable data
  • pure functions are deterministic, no observable side effects
  • external variables NOT passed as arguments can be non-pure as that variable's state can change at execution
  • reading external files is not pure, those files can be changed
  • random number generation can not be pure
  • pure functions do not modify globals or the things they take in as arguments or if they do, just return values from them without assignment
  • .map() is a pure function since it doesn't alter the original array
  • recursion can be used for loops to make them pure by keeping variables immutable
  • memoizing functions can let you pass and stack them around
  • higher order functions take in functions as an argument
  • you can pass a func to .filter() if it's formatted right
  • consistent use of constants and returning back new values/arays preents over-writing and maintains immutable data

Refactoring JavaScript for Performance and Readability

  • hash map a key to a location in the hash table
  • tbl.set(key, val)
  • early function returns to see if a bad state (no user) to reduce wasted time
  • set vars during loops or while other tasks are performed to make code self documenting (avoiding thing.object.way[0].item