-
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy path4-methods.js
More file actions
33 lines (28 loc) · 705 Bytes
/
4-methods.js
File metadata and controls
33 lines (28 loc) · 705 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
31
'use strict';
const methods = iface => {
// Introspect all properties of iface object and
// extract function names and number of arguments
// For example: {
// m1: x => [x],
// m2: function (x, y) {
// return [x, y];
// },
// m3(x, y, z) {
// return [x, y, z];
// }
// will return: [
// ['m1', 1],
// ['m2', 2],
// ['m3', 3]
// ]
const methodNames = Object.keys(iface);
const methodsArray = methodNames.reduce((acc, methodName) => {
const prop = iface[methodName];
if (typeof prop === 'function') {
acc.push([methodName, prop.length]);
}
return acc;
}, []);
return methodsArray;
};
module.exports = { methods };