View map_wihout_loop_ifs.js
// here condR === undefined
const falsy = (condL, condR) => condL !== condR;
const map = (fn, [first, ...rest]) =>
(falsy(first) && []) && [fn(first), ...map(fn, rest)];
console.log(':)', map((x) => (x + x), [1, 2, 3]));
View gist:74516ccb0f9ca48dfa4a
// char => char
function closingTag(char) {
return {
'(': ')',
'{': '}',
'[': ']'
}[char];
}
// char => boolean
View gist:f40ed918cb5102438500
function match_brackets(str){
var stack = [],
lookup = {
//key : value pairs
'(' : ')',
'{' : '}',
'[' : ']',
},
_keys = Object.keys(lookup),
View gist:0de000098c15482d52ba
function train(fileName, splitter) {
var parts = fs.readFileSync(fileName).toString().split(splitter).map(function (el) {
return _.prepare(el).split(' ');
});
return mergeBig(parts);
}
View gist:343604fa29a1b223dfde
// simples would be return dataBase[word];
// string => array
function predict(word) {
var needle = dataBase[word];
if (!needle) {
return [];
}
var total = _.reduce(needle, function (acc, el) {
View gist:274701f952f1452eb0ee
var dataBase; // cache
function mergeBig(texts) {
texts = texts || text;
return q.all(texts.map(function (el) {
return task(el)
.reduce(bigramArray)
.run()
})).then(function reducer(data) {
View gist:ebaf3ddec5c1b91f9e16
function mergeSmall() {
var task1 = task(ch01)
.reduce(bigramArray)
.run();
var task2 = task(ch02)
.reduce(bigramArray)
.run();
return q.all([task1, task2]).then(function (data) {
View gist:502b6e7a0038561015e8
function bigramText(arr) {
return arr.reduce(bigramArray);
}
function bigramArray(acc, word, i, arr) {
if (1 === i) {
acc = {last: acc, out: {}};
}
var out = acc.out;
var last = acc.last;
View gist:207e6e9e1bbb1412e2e1
var jsSpark = require('js-spark')({workers: 4});
var task = jsSpark.jsSpark;
var q = jsSpark.q;
var _ = require('lodash');
var lib = require('./lib')(_);
_.mixin(lib);
var fs = require('fs');
var DRACULA = './data/text/dracula/';
View gist:eaf0d9e5c3c5cf5a84fc
/**
* Created by syzer on 4/8/2015.
*/
module.exports = function (_) {
'use strict';
return {
objectMerger: objectMerger,
mergeObjectsInArr: mergeObjectsInArr,
objToSortedArr: objToSortedArr,