{"size": 3598, "ext": "js", "max_stars_repo_path": "lib/stats.js", "max_stars_repo_name": "cicada-solvers/idkfa", "max_stars_repo_stars_event_min_datetime": "2015-12-16T17:39:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-03T01:40:19.000Z", "max_issues_repo_path": "lib/stats.js", "max_issues_repo_name": "cicada-solvers/idkfa", "max_issues_repo_issues_event_min_datetime": "2015-12-12T15:47:16.000Z", "max_issues_repo_issues_event_max_datetime": "2016-04-19T17:45:00.000Z", "max_forks_repo_path": "lib/stats.js", "max_forks_repo_name": "cicada-solvers/idkfa", "max_forks_repo_forks_event_min_datetime": "2016-01-10T19:32:31.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-10T17:57:36.000Z"}
{"max_stars_count": 31, "max_issues_count": 5, "max_forks_count": 19, "avg_line_length": 29.7355371901, "max_line_length": 171, "alphanum_fraction": 0.5369649805}

const Config    = require('../config');
const Gematria  = require('./gematria');
const Key       = require('./key');
const Source    = require('./source');
const Util      = require('./util');

const Stats = (() =>
{
    /**
     * Gets the word lengths.
     *
     * @param      {array}  x       foobar
     * @return     {array}  The word lengths.
     */
    const getWordLengths = x => x.map(y => Util.isArray(y) && Util.isArray(y[0]) ? getWordLengths(y) : y.length);

    /**
     * Gets the character count.
     *
     * @param      {<type>}  arrText  The arr text
     * @return     {<type>}  The character count.
     */
    const getCharCount = arrText => Util.flatten(arrText).length;

    /**
     * Gets the word count.
     *
     * @param      {<type>}  arrText  The arr text
     * @return     {<type>}  The word count.
     */
    const getWordCount = arrText => Util.flattenTo1st(arrText).length;

    /**
     * Gets the character at.
     *
     * @param      {<type>}  arrText    The arr text
     * @param      {<type>}  intOffset  The int offset
     * @return     {<type>}  The character at.
     */
    const getCharAt = (arrText, intOffset) => Util.flatten(arrText)[intOffset];

    /**
     * Gets the word at.
     *
     * @param      {<type>}  arrText    The arr text
     * @param      {<type>}  intOffset  The int offset
     * @return     {<type>}  The word at.
     */
    const getWordAt = (arrText, intOffset) => Util.flattenTo1st(arrText)[intOffset];

    /**
     * Gets the prime value.
     *
     * @param      {<type>}  n                    { parameter_description }
     * @param      {<type>}  arrInvertProperties  The arr invert properties
     * @return     {<type>}  The prime value.
     */
    const getPrimeValue = (n, arrInvertProperties) =>
    {
        let prime = Gematria.toPrime(arrInvertProperties)(n);

        return prime ? prime : 0;
    };

    /**
     * { lambda_description }
     *
     * @param      {<type>}  arr                  The arr
     * @param      {<type>}  arrInvertProperties  The arr invert properties
     * @return     {<type>}  { description_of_the_return_value }
     */
    const deepSum = (arr, arrInvertProperties) => arr.reduce((s, n) => s + (Util.isArray(n) ? deepSum(n, arrInvertProperties) : getPrimeValue(n, arrInvertProperties)), 0);

    /**
     * Gets the checksum.
     *
     * @param      {<type>}  arrText  The arr text
     * @return     {<type>}  The checksum.
     */
    const getChecksum = arrText => [deepSum(arrText, []), deepSum(arrText, ['prime'])];

    /**
     * Gets the frequency.
     *
     * @param      {<type>}  arr     The arr
     * @return     {<type>}  The frequency.
     */
    const getFrequency = arr => [...new Set(arr)].map(x => [x, arr.filter(y => y === x).length]);

    /**
     * Gets the ioc.
     *
     * @param      {<type>}  arrText  The arr text
     * @return     {Array}   The ioc.
     */
    const getIOC = arrText =>
    {
        let arrGraphs           = Util.flatten(arrText);
        let intGraphsLength     = arrGraphs.length;
        let arrGraphFrequency   = getFrequency(arrGraphs);

        let intFrequency = arrGraphFrequency.reduce((sum, next) => sum + next[1] * (next[1] - 1), 0);

        return [intFrequency / (intGraphsLength * (intGraphsLength - 1) / Gematria.tableLength), intFrequency / (intGraphsLength * (intGraphsLength - 1))];
    };

    return {
        getFrequency,
        getCharCount,
        getWordCount,
        getCharAt,
        getWordAt,
        getChecksum,
        getIOC
    };

})();

module.exports = Stats;
