<commit_before>var memoize = function (fn, results) {
    var memo = [0, 1];

    // closure
    return function compute(n) {
        var current = memo[n];

        // avoid false truthy test by ensuring type if a number
        // instead of !current as it could be 0|1
        if (typeof current !== 'number') {
            current = fn(compute, n);
            memo[n] = results[results.length] = current;
        }

        return current;
    };
};

var cb = function(fn, n) {
    var results = fn(n - 1) + fn( n - 2 );
    return results;
};

var sequence = [];
var printSequence = memoize(cb, sequence);
printSequence(10);

console.log(sequence);
<commit_msg>Converted to OO implementation<commit_after>'use strict';

var Fibonacci = function Fibonacci() {
    if (!(this instanceof Fibonacci)) {
        return new Fibonacci();
    }

    this.memo = null;
};

/**
 * Resets the memo before each run
 */
Fibonacci.prototype.reset = function reset() {
    this.memo = [0, 1];
};

/**
 * Generates a sequence of fibonacci numbers
 * computed to nth upper bound.
 *
 * @return void
 */
Fibonacci.prototype.generate = function generate(n) {
    this.reset();

    var self = this;
    var idx = 0;

    return run.call(this, n);
};

/**
 * Returns the sequence of Fibonacci numbers computed
 * to nth bound.
 *
 * @return void
 */
Fibonacci.prototype.getSequence = function getSequence() {
    return this.memo;
};

/*** Private Methods ***/
var compute = function(fn, n) {
    var results = fn(n - 1) + fn( n - 2 );
    return results;
};

var run = function run(n) {
    var current = this.memo[n];
    if (typeof(current) !== 'number') {
        current = compute(run.bind(this), n);
        this.memo[n] = current;
    }

    return current;
};

var fib = new Fibonacci();
var max = fib.generate(10);
console.log('sequence: ', fib.getSequence());
console.log('max: ', max);


// var memoize = function (fn, results) {
//     var memo = [0, 1];

//     // closure
//     return function compute(n) {
//         var current = memo[n];

//         // avoid false truthy test by ensuring type if a number
//         // instead of !current as it could be 0|1
//         if (typeof current !== 'number') {
//             current = fn(compute, n);
//             memo[n] = results[results.length] = current;
//         }

//         return current;
//     };
// };

// var compute = function(fn, n) {
//     var results = fn(n - 1) + fn( n - 2 );
//     return results;
// };

// var sequence = [];
// var printSequence = memoize(compute, sequence);
// printSequence(10);
// console.log(sequence);

{'fraction_non_alphanumeric': 0.15538461538461537, 'fraction_numerical': 0.008846153846153846, 'mean_word_length': 2.296577946768061, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6188688', 'n_tokens_mistral': 847, 'n_tokens_neox': 820, 'n_words': 250}