How to add in programming languages


This is a tongue-in-cheek attempt to expose programming language expressiveness. 1. Scheme Characters needed to add n digits: n + 3 Prefix notation allows passing in multiple operands Prefix notation is not popular 2. JavaScript/Python/Ruby/Octave/Matlab Characters needed to add n digits: n + (n - 1) Very simple and generally accepted Infix form requires two operands leading to (n - 1) operators … Continue reading How to add in programming languages

JavaScript’s Array.prototype.reduce()


Programming involves manipulating collections of various things. Operations on collections include aggregating values, conversion into other formats and data replacement. Let's take a sum of array elements using the typical imperative style. Here's another example to flatten a 2-d array. One liner (inpiration) Both code snippets can be written more succinctly using the fold concept from functional programming. The snippets … Continue reading JavaScript’s Array.prototype.reduce()