5639.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. exports.id = 5639;
  3. exports.ids = [5639];
  4. exports.modules = {
  5. /***/ 5639:
  6. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  7. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8. /* harmony export */ "Hj": () => (/* binding */ areArraysEqual),
  9. /* harmony export */ "sj": () => (/* binding */ removeItemFromArray),
  10. /* harmony export */ "sp": () => (/* binding */ mergeTwoArraysUniquely)
  11. /* harmony export */ });
  12. /* unused harmony exports numbersToStringsArray, stringsToNumbersArray */
  13. /**
  14. * Convert an array of numbers to an array of strings.
  15. *
  16. * @param {number[]} numbersArray
  17. * @returns {string[]}
  18. */ const numbersToStringsArray = (numbersArray)=>numbersArray.map((number)=>String(number));
  19. /**
  20. * Convert an array of strings to an array of numbers.
  21. *
  22. * @param {string[]} stringsArray
  23. * @returns {number[]}
  24. */ const stringsToNumbersArray = (stringsArray)=>stringsArray.map((string)=>Number(string));
  25. /**
  26. * Check whether 2 arrays are equal or not irrespective of
  27. * their order. We need to create a copy of both arrays first
  28. * since sort() overwrites the original array.
  29. *
  30. * @param {T[]} array1
  31. * @param {T[]} array2
  32. * @returns {boolean}
  33. */ const areArraysEqual = (array1, array2)=>{
  34. // If the arrays have different lengths, they are not equal
  35. if (array1?.length !== array2?.length) return false;
  36. // Create a map of the first array, with each element as a key and true as the value
  37. const array1Map = new Map();
  38. array1.map((item)=>array1Map.set(item, true));
  39. // Loop through the second array
  40. for(let i = 0; i < array2.length; i += 1){
  41. // If an element in the second array is not found in the map of the first array, they are not equal
  42. if (array1Map.get(array2[i]) == null) return false;
  43. // Delete the element from the map of the first array
  44. array1Map.delete(array2[i]);
  45. }
  46. // If the map of the first array has no elements left, the arrays are equal
  47. return array1Map.size === 0;
  48. };
  49. /**
  50. * Remove `itemToRemove` from `array`
  51. *
  52. * @example
  53. * removeItemFromArray(1, [1,2,3]) // returns [2,3]
  54. *
  55. * @param {T} itemToRemove
  56. * @param {T[]} array
  57. * @returns {boolean}j
  58. */ const removeItemFromArray = (itemToRemove, array)=>array.filter((item)=>item !== itemToRemove);
  59. /**
  60. * Merge items of two arrays where each item is unique.
  61. *
  62. * @param {T[]} array1
  63. * @param {T[]} array2
  64. * @returns {T[]}
  65. */ const mergeTwoArraysUniquely = (array1, array2)=>{
  66. return Array.from(new Set(array1.concat(array2)));
  67. };
  68. /***/ })
  69. };
  70. ;
  71. //# sourceMappingURL=5639.js.map