CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
index.js70 linesDownload Raw Back to for-each
1'use strict';2 3var isCallable = require('is-callable');4 5var toStr = Object.prototype.toString;6var hasOwnProperty = Object.prototype.hasOwnProperty;7 8/** @type {<This, A extends readonly unknown[]>(arr: A, iterator: (this: This | void, value: A[number], index: number, arr: A) => void, receiver: This | undefined) => void} */9var forEachArray = function forEachArray(array, iterator, receiver) {10    for (var i = 0, len = array.length; i < len; i++) {11        if (hasOwnProperty.call(array, i)) {12            if (receiver == null) {13                iterator(array[i], i, array);14            } else {15                iterator.call(receiver, array[i], i, array);16            }17        }18    }19};20 21/** @type {<This, S extends string>(string: S, iterator: (this: This | void, value: S[number], index: number, string: S) => void, receiver: This | undefined) => void} */22var forEachString = function forEachString(string, iterator, receiver) {23    for (var i = 0, len = string.length; i < len; i++) {24        // no such thing as a sparse string.25        if (receiver == null) {26            iterator(string.charAt(i), i, string);27        } else {28            iterator.call(receiver, string.charAt(i), i, string);29        }30    }31};32 33/** @type {<This, O>(obj: O, iterator: (this: This | void, value: O[keyof O], index: keyof O, obj: O) => void, receiver: This | undefined) => void} */34var forEachObject = function forEachObject(object, iterator, receiver) {35    for (var k in object) {36        if (hasOwnProperty.call(object, k)) {37            if (receiver == null) {38                iterator(object[k], k, object);39            } else {40                iterator.call(receiver, object[k], k, object);41            }42        }43    }44};45 46/** @type {(x: unknown) => x is readonly unknown[]} */47function isArray(x) {48    return toStr.call(x) === '[object Array]';49}50 51/** @type {import('.')._internal} */52module.exports = function forEach(list, iterator, thisArg) {53    if (!isCallable(iterator)) {54        throw new TypeError('iterator must be a function');55    }56 57    var receiver;58    if (arguments.length >= 3) {59        receiver = thisArg;60    }61 62    if (isArray(list)) {63        forEachArray(list, iterator, receiver);64    } else if (typeof list === 'string') {65        forEachString(list, iterator, receiver);66    } else {67        forEachObject(list, iterator, receiver);68    }69};70 
basant307/AI_Governance_Project · CoolFace