## Coding Zen in all the strange places

I continue to return to Zen as a way to reach peace with myself. Zen encourages introspection and meditation alongside expressive acts such as calligraphy. The core of Zen calligraphy, such that I understand it, is to cultivate the beginner’s mind. The expert mind is packed with presumption; while an expert mind has a powerful ability to categorize a problem, such that it can immediately a ready-made solution, this procedural reduction prevents it from naive consideration of the actual problem as presented.

This is evident at work: I think “Aha! This task is in fact this problem with this solution!,” and then I solve it. I get faster, but I don’t grow: practice reinforces dogma. Practice strengthens your current paradigm inhibits personal development.

I bought If Hemingway Wrote JavaSciript by Angus Coll from a Humble Bundle a few months ago. The book’s comparative approaches to the same simple problem inspired me to fuse Zen naïvety and functional JavaScript. Michael Fogus’ approach in Functional JavaScript underlies my recent series of JavaScript snippets.

Snippets should be taken at face value: exercises in a base level of code that encapsulates knowledge and naive practice. What is a map? What is an elegant way to find factorials? The goal is to improve my ability to problem-solve with JavaScript without preconception.

``````function range(start, end) {
if (!end) {
end = start;
start = 1;
}

if (start > end) {
[start, end] = [end, start];
}

return [...Array(end + 1).keys()].slice(start);
}

function reduce(arr, sum, callback) {
return !arr.length ? sum : reduce(arr.slice(1), callback(arr[0], sum), callback);
}

let adder = (number, sum) => number + sum,
multiplier = (number, sum) => number * sum,
numbers = range(10);