-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
49 lines (40 loc) · 807 Bytes
/
index.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*!
* longest <https://github.com/jonschlinkert/longest>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
module.exports = function(arr) {
if (!Array.isArray(arr)) {
throw new TypeError('expected an array');
}
var len = arr.length;
if (len === 0) {
return undefined;
}
var val = arr[0];
if (typeof val === 'number') {
val = String(val);
}
var longest = val.length;
var idx = 0;
while (++idx < len) {
var ele = arr[idx];
if (ele == null) {
continue;
}
if (typeof ele === 'number') {
ele = String(ele);
}
var elen = ele.length;
if (typeof elen !== 'number') {
continue;
}
if (elen > longest) {
longest = elen;
val = ele;
}
}
return val;
};