-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (17 loc) · 517 Bytes
/
index.js
File metadata and controls
21 lines (17 loc) · 517 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*!
* array-initial <https://github.com/jonschlinkert/array-initial>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT license.
*/
var isNumber = require('is-number');
var slice = require('array-slice');
module.exports = function arrayInitial(arr, num) {
if (!Array.isArray(arr)) {
throw new Error('array-initial expects an array as the first argument.');
}
if (arr.length === 0) {
return null;
}
return slice(arr, 0, arr.length - (isNumber(num) ? num : 1));
};