<commit_before>/**
 * HashMap - HashMap JavaScript class inspired by JDK 8 HashMap class
 * @author <NAME> <<EMAIL>>
 * @version 0.0.1
 * Homepage: https://github.com/francisdesjardins/hashmap
 *
 * Key hashing, tests and 'did not knew that' highly inspired by
 * - HashMap by <NAME> https://github.com/flesler/hashmap
 */

'use strict';

// Module dependencies.

var hasOwnProperty = Object.prototype.hasOwnProperty;
var requireFunction = require('./utils').requireFunction;
var split = String.prototype.split;
var type = require('./utils').typeOf;
var createKey = require('private-parts').createKey;

// Module variables.

var privates = createKey({
    current: null,
    currentIndex: -1,
    target: null,
    targetIndex: -1
});

// Module definition.

/**
 * @param {Array|string} target
 * @param {Function} [remove]
 * @constructor
 */
function Iterator(target, remove) {
    privates(this).target = (type(target) === 'string' ? split.call(target, '') : target);
    privates(this).targetIndex = target.length - 1;

    if (remove) {
        requireFunction(remove, '"remove" is not a function');

        this.remove = function () {
            remove.apply(this, [privates(this).currentIndex, privates(this).current]);
        };
    }
}

/**
 * Execute the given action on each remaining entries
 * @param action
 * @param {Object} [context=this]
 */
Iterator.prototype.forEachRemaining = function (action, context) {
    requireFunction(action, '"action" is not a function');

    context = context || this;

    while (this.hasNext()) {
        action.apply(context, [this.next()]);
    }
};

/**
 * Returns true if the next call to 'next' would not throw an exception
 * @returns {!boolean}
 */
Iterator.prototype.hasNext = function () {
    return privates(this).currentIndex < privates(this).targetIndex;
};

/**
 * Returns the next entry
 * @returns {!*}
 * @throws RangeError
 */
Iterator.prototype.next = function () {
    if (!this.hasNext()) {
        throw new RangeError('the iteration has no more elements');
    }

    privates(this).current = privates(this).target[privates(this).currentIndex += 1];

    return privates(this).current;
};

/**
 * Removes the current entry from the map
 * @throws Error
 */
Iterator.prototype.remove = function () {
    throw new Error('"remove" is not supported');
};

// Module exports.

module.exports = Iterator;
<commit_msg>IMPROVEMENT - constructor checks if target is Array or string<commit_after>/**
 * HashMap - HashMap JavaScript class inspired by JDK 8 HashMap class
 * @author <NAME> <<EMAIL>>
 * @version 0.0.1
 * Homepage: https://github.com/francisdesjardins/hashmap
 *
 * Key hashing, tests and 'did not knew that' highly inspired by
 * - HashMap by <NAME> https://github.com/flesler/hashmap
 */

'use strict';

// Module dependencies.

var hasOwnProperty = Object.prototype.hasOwnProperty;
var requireFunction = require('./utils').requireFunction;
var requireInstanceOf = require('./utils').requireInstanceOf;
var split = String.prototype.split;
var type = require('./utils').typeOf;
var createKey = require('private-parts').createKey;

// Module variables.

var privates = createKey({
    current: null,
    currentIndex: -1,
    target: null,
    targetIndex: -1
});

// Module definition.

/**
 * @param {Array|string} target
 * @param {Function} [remove]
 * @constructor
 * @throws TypeError
 */
function Iterator(target, remove) {
    privates(this).target = (type(target) === 'string' ? split.call(target, '') : target);
    privates(this).targetIndex = target.length - 1;

    requireInstanceOf(privates(this).target, Array, '"target" must be an Array or a string');

    if (remove) {
        requireFunction(remove, '"remove" is not a function');

        this.remove = function () {
            remove.apply(this, [privates(this).currentIndex, privates(this).current]);
        };
    }
}

/**
 * Execute the given action on each remaining entries
 * @param action
 * @param {Object} [context=this]
 */
Iterator.prototype.forEachRemaining = function (action, context) {
    requireFunction(action, '"action" is not a function');

    context = context || this;

    while (this.hasNext()) {
        action.apply(context, [this.next()]);
    }
};

/**
 * Returns true if the next call to 'next' would not throw an exception
 * @returns {!boolean}
 */
Iterator.prototype.hasNext = function () {
    return privates(this).currentIndex < privates(this).targetIndex;
};

/**
 * Returns the next entry
 * @returns {!*}
 * @throws RangeError
 */
Iterator.prototype.next = function () {
    if (!this.hasNext()) {
        throw new RangeError('the iteration has no more elements');
    }

    privates(this).current = privates(this).target[privates(this).currentIndex += 1];

    return privates(this).current;
};

/**
 * Removes the current entry from the map
 * @throws Error
 */
Iterator.prototype.remove = function () {
    throw new Error('"remove" is not supported');
};

// Module exports.

module.exports = Iterator;

{'fraction_non_alphanumeric': 0.14708233413269384, 'fraction_numerical': 0.0031974420463629096, 'mean_word_length': 3.5833333333333335, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 4, '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': '1149374', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1456, 'n_words': 409}