UNPKG

locutus

Version:

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

32 lines (31 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.array_diff_key = array_diff_key; const _phpTypes_ts_1 = require("../_helpers/_phpTypes.js"); function array_diff_key(arr1, ...arrays) { // discuss at: https://locutus.io/php/array_diff_key/ // original by: Ates Goral (https://magnetiq.com) // revised by: Brett Zamir (https://brett-zamir.me) // input by: Everlasto // example 1: array_diff_key({red: 1, green: 2, blue: 3, white: 4}, {red: 5}) // returns 1: {"green":2, "blue":3, "white":4} // example 2: array_diff_key({red: 1, green: 2, blue: 3, white: 4}, {red: 5}, {red: 5}) // returns 2: {"green":2, "blue":3, "white":4} const retArr = {}; if (arrays.length < 1) { return retArr; } const arr1Object = (0, _phpTypes_ts_1.toPhpArrayObject)(arr1); arr1keys: for (const [k1, arr1Value] of (0, _phpTypes_ts_1.entriesOfPhpAssoc)(arr1Object)) { for (const nextArray of arrays) { const arr = (0, _phpTypes_ts_1.toPhpArrayObject)(nextArray); for (const [k] of (0, _phpTypes_ts_1.entriesOfPhpAssoc)(arr)) { if (k === k1) { continue arr1keys; } } } retArr[k1] = arr1Value; } return retArr; }