Exemplo n.º 1
0
module.exports = function (object, keyArray) {
  var length = keyArray.length
  var parent = get(object, keyArray.slice(0, length - 1))
  if (parent === undefined) {
    throw new TypeError()
  } else {
    delete parent[keyArray[length - 1]]
    return true
  }
}
Exemplo n.º 2
0
var lastAtDepth = function recurse(context, depth, keyArray) {
  if (depth === 0) {
    return keyArray;
  } else {
    var lastFormIndex = last(context.content, function(element) {
      return element.hasOwnProperty('form');
    });
    if (lastFormIndex === -1) {
      throw new Error('No form at the given depth');
    }
    var additionalKeys = ['content', lastFormIndex, 'form'];
    return recurse(
      get(context, additionalKeys),
      depth - 1,
      keyArray.concat(additionalKeys)
    );
  }
};