JSFiddle - React, Tailwind, and code Playground

by Joshua McNeese

HTML

<script src="https://raw.githubusercontent.com/lodash/lodash/4.6.1/dist/lodash.js"></script>

Babel + JSX

const fibs = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34];
const add = (x, y) => x + y;
const subtract = (x, y) => x - y;
const multiply = (x, y) => x * y;
const divide = (x, y) => x / y;
const map = (arr, fn) => arr.map(fn);
const reduce = (arr, fn) => arr.reduce(fn);
const count = arr => arr.length;
const square = x => Array.isArray(x) ? map(x, square) : multiply(x, x);
const sum = arr => reduce(arr, add);
const mean = arr => divide(
  sum(arr), 
  count(arr)
);
const standardDeviation = arr => subtract(
  mean(square(arr)),
  square(mean(arr))
);
console.log('fp', standardDeviation(fibs)); 
// 109.55999999999999

_.mixin({
	multiply: (x, y) => x * y,
  divide: (x, y) => x / y,
  square: x => _.isArray(x) ? _.map(x, _.square) : _.multiply(x, x),
  standardDev: arr => _.subtract(_.mean(_.square(arr)), _.square(_.mean(arr)))
});
console.log('lodash', _.standardDev(fibs)); 
// 109.55999999999999