StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics
https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
4 years ago
|
import identity from './identity';
|
||
|
import { isArray, isObject } from './inspect';
|
||
|
import { clone } from './object';
|
||
|
/**
|
||
|
* Copies props from one array/object to a new array/object. Prop values
|
||
|
* are also cloned as new references to prevent possible mutation of original
|
||
|
* prop object values. Optionally accepts a function to transform the prop name.
|
||
|
*
|
||
|
* @param {[]|{}} props
|
||
|
* @param {Function} transformFn
|
||
|
*/
|
||
|
|
||
|
var copyProps = function copyProps(props) {
|
||
|
var transformFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : identity;
|
||
|
|
||
|
if (isArray(props)) {
|
||
|
return props.map(transformFn);
|
||
|
} // Props as an object.
|
||
|
|
||
|
|
||
|
var copied = {};
|
||
|
|
||
|
for (var prop in props) {
|
||
|
/* istanbul ignore else */
|
||
|
// eslint-disable-next-line no-prototype-builtins
|
||
|
if (props.hasOwnProperty(prop)) {
|
||
|
// If the prop value is an object, do a shallow clone to prevent
|
||
|
// potential mutations to the original object.
|
||
|
copied[transformFn(prop)] = isObject(props[prop]) ? clone(props[prop]) : props[prop];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return copied;
|
||
|
};
|
||
|
|
||
|
export default copyProps;
|