all files / scour/utilities/ clone_without.js

100% Statements 9/9
100% Branches 6/6
100% Functions 1/1
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19          12×          
/**
 * Clones an object but misses a key.
 */
 
module.exports = function cloneWithout (object, key) {
  if (Array.isArray(object)) {
    return object.slice(0, +key).concat(object.slice(+key + 1))
  } else {
    var result = {}
    key = '' + key
    for (var k in object) {
      if (object.hasOwnProperty(k) && key !== k) {
        result[k] = object[k]
      }
    }
    return result
  }
}