index.js
function setByPath(target, path, value) {
  path = pathToArray(path);

  if (! path.length) {
    return value;
  }

  const key = path[0];
  if (isNumber(key)) {
    if (! Array.isArray(target)) {
      target = [];
    }
  }
  else if (! isObject(target)) {
    target = {};
  }

  if (path.length > 1) {
    target[key] = setByPath(target[key], path.slice(1), value);
  }
  else {
    target[key] = value;
  }

  return target;
}
function setByPath(target, path, value) {
  path = pathToArray(path);

  if (! path.length) {
    return value;
  }

  const key = path[0];
  if (isNumber(key)) {
    if (! Array.isArray(target)) {
      target = [];
    }
  }
  else if (! isObject(target)) {
    target = {};
  }

  if (path.length > 1) {
    target[key] = setByPath(target[key], path.slice(1), value);
  }
  else {
    target[key] = value;
  }

  return target;
}
function setByPath ( target , path , value ) { path = pathToArray ( path ) ; if ( ! path . length ) { return value ; } const key = path [ 0 ] ; if ( isNumber ( key ) ) { if ( ! Array . isArray ( target ) ) { target = [ ] ; } } else if ( ! isObject ( target ) ) { target = { } ; } if ( path . length > 1 ) { target [ key ] = setByPath ( target [ key ] , path . slice ( 1 ) , value ) ; } else { target [ key ] = value ; } return target ; }
setByPath - Set deeply nested value into target object. If nested properties
are not an objects or not exists creates them.

@param {Object} target Parent object.
@param {Path} path Array of path segments.
@param {*} value Value to set.
@return {void}
setByPath - Set deeply nested value into target object . If nested properties are not an objects or not exists creates them .