forked from Tinkoff/utils.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcat.ts
More file actions
25 lines (23 loc) · 700 Bytes
/
concat.ts
File metadata and controls
25 lines (23 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { concat } from '../typings/types';
import curryN from '../function/curryN';
import isArray from '../is/array';
/**
* Returns the result of concatenating the given arrays or strings.
*
* @param {Array|String} a The first list
* @param {Array|String} b The second list
* @return {Array|String} A list consisting of the elements of `firstList` followed by the elements of
* `secondList`.
*
* @example
*
* concat('ABC', 'DEF'); // 'ABCDEF'
* concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
* concat([], []); //=> []
*/
export default curryN(2, (a = [], b = []) => {
if (isArray(a)) {
return a.concat(b);
}
return a + b;
}) as typeof concat