* Return the given array trimmed to the given length. The original array is also trimmed. * @example arrayTrim([1, 2, 3, 4], 2) -> [1, 2] * * @param {Array} array * @param {Number} length * @returns {Array}
(array, length)
| 1462 | * @returns {Array} |
| 1463 | */ |
| 1464 | static arrayTrim(array, length) { |
| 1465 | const arrLength = array.length; |
| 1466 | if (arrLength === 0 || length > arrLength) { |
| 1467 | // Also manage the case where `length` is higher than the current length |
| 1468 | return array; |
| 1469 | } |
| 1470 | |
| 1471 | if (length < 0) { |
| 1472 | return []; |
| 1473 | } |
| 1474 | |
| 1475 | array.length = parseInt(length, 10); |
| 1476 | |
| 1477 | return array; |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * Merge all the given arrays by keeping only unique elements, and return an array with de-duplicated values. |