forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (28 loc) · 782 Bytes
/
Copy pathindex.js
File metadata and controls
30 lines (28 loc) · 782 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
26
27
28
29
30
module.exports = values;
/*
values({a: 4, c: 8}); // [4, 8]
values({a: {aa: 2}, b: {bb: 4}}); // [{aa: 2}, {bb: 4}]
values({}); // []
values([1, 2, 3]); // [1, 2, 3]
values(function(a, b) {return a + b;}); // []
values(String('hello')); // []
values(1); // throw exception
values(true); // throw exception
values(undefined); // throw exception
values(null); // throw exception
*/
function values(obj) {
var result = [];
if (Array.isArray(obj)) {
return obj.slice(0);
}
if (typeof obj == 'object' || typeof obj == 'function') {
var keys = Object.keys(obj);
var len = keys.length;
for (var i = 0; i < len; i++) {
result.push(obj[keys[i]]);
}
return result;
}
throw new Error('argument to `values` must be an object');
}