UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

1 lines 1.29 kB
{"version":3,"file":"index.mjs","sources":[""],"sourcesContent":["export type TGetIntersectionArgs = Parameters<typeof getIntersection>;\r\n\r\nexport type TGetIntersectionReturn = ReturnType<typeof getIntersection>;\r\n\r\n/**\r\n * Gets Array of intersection of two given Arrays\r\n * @template T\r\n * @param {Array<T>} arr1 first source Array\r\n * @param {Array<T>} arr2 second source Array\r\n * @returns {Array<T>}\r\n * @throws {TypeError} getIntersection: arr1 and arr2 must be arrays\r\n * @example\r\n * // How to get an intersection of two Arrays?\r\n * const arr1 = [ 1, 2, 3 ];\r\n * const arr2 = [ 2, 3, 4, 5 ];\r\n * const intersection = getIntersection(arr1, arr2);\r\n * console.log(intersection); // => [ 2, 3 ]\r\n */\r\nexport const getIntersection = <T>(arr1: T[], arr2: T[]): T[] => {\r\n if (!Array.isArray(arr1) || !Array.isArray(arr2)) {\r\n throw new TypeError(\"getIntersection: arr1 and arr2 must be arrays\");\r\n }\r\n return [ ...arr1 ].filter((val) => arr2.includes(val));\r\n};\r\n"],"names":["getIntersection","arr1","arr2","Array","isArray","TypeError","filter","val","includes"],"mappings":";;;;;;;;;;;;;;MAkBaA,gBAAkBA,CAAIC,KAAWC,QAC5C,IAAKC,MAAMC,QAAQH,QAAUE,MAAMC,QAAQF,MACzC,MAAM,IAAIG,UAAU,iDAEtB,MAAO,IAAKJ,MAAOK,OAAQC,KAAQL,KAAKM,SAASD"}