Repository URL to install this package:
|
Version:
1.2.1 ▾
|
"use strict";
// @todo not sure if this is fine to import here or if we move this elsewhere
const _require = require("../../exotic"),
EMPTY_ARRAY = _require.EMPTY_ARRAY,
EMPTY_OBJ = _require.EMPTY_OBJ,
isArray = _require.isArray,
isObj = _require.isObj;
if (process.env.NODE_ENV === 'development') {
try {
// exotic.EMPTY_ARRAY.isEmpty === true
// exotic.EMPTY_ARRAY.isEmpty === true
Object.defineProperty(Array.prototype, 'IS_EMPTY', {
enumerable: false,
configurable: false,
get() {
return this === EMPTY_ARRAY;
}
});
Object.defineProperty(Object.prototype, 'IS_EMPTY', {
enumerable: false,
configurable: false,
get() {
return this === EMPTY_OBJ;
}
});
} catch (notWritableException) {// ignore, dev
}
}
/**
* @param {Object} props
* @return {Array<any>}
*/
const fromPropsToLongestArray = props => {
// let best = ['empty']
let best = [];
Object.keys(props) // should be able to sort based on common naming
// should be able to do a more fancy reduce or sortby .length & .pop/find
.forEach(key => {
const list = props[key];
if (isArray(list) === false) {
return;
}
if (list.length > best.length) {
best = list;
}
});
return best;
}; // @example
// const one = {
// longest: [1],
// shortest: [],
// }
// const two = {
// longest: [1, 2, 3, 4],
// shortest: exotic.EMPTY_ARRAY,
// medium: [1, 2, 3]
// }
fromPropsToLongestArray.fromPropsToLongestArray = fromPropsToLongestArray;
module.exports = fromPropsToLongestArray;