import _ from "lodash";
export const cloneAny = (original) => {
  let cloned = null;
  if (Array.isArray(original)) {
    cloned = cloneArray(original);
  } else if (_.isObject(original)) {
    cloned = cloneObject(original);
  } else {
    cloned = original;
  }
  return cloned;
};

const cloneArray = (originalArray) => {
  let clonedArray = [];
  for (let c = 0; c < originalArray.length; c++) {
    let arrValue = originalArray[c];
    if (Array.isArray(arrValue)) {
      clonedArray.push(cloneArray(arrValue));
    } else if (_.isObject(arrValue)) {
      clonedArray.push(cloneObject(arrValue));
    } else {
      clonedArray.push(arrValue);
    }
  }
  return clonedArray;
};

const cloneObject = (originalObject) => {
  let clonedObject = {};
  for (let prop in originalObject) {
    let value = originalObject[prop];
    if (Array.isArray(value)) {
      clonedObject[prop] = cloneArray(value);
    } else if (_.isObject(value)) {
      clonedObject[prop] = cloneObject(value);
    } else {
      clonedObject[prop] = value;
    }
  }
  return clonedObject;
};
