function deleteChildren(parent, depth) {
  if (parent.children) {
    if (depth === 1) {
      for (let i = 0; i < parent.children.length; i++) {
        delete parent.children[i].children;
      }
    } else if (depth > 1) {
      for (let i = 0; i < parent.children.length; i++) {
        deleteChildren(parent.children[i], depth - 1);
      }
    }
  }

  return parent;
} // deleteChildren
/**
 * Recursive function to prune children from a subject in order to return a
 * subject hierarchy with the specified depth.
 *
 * @param {Instance} parent - The subject whose children may be deleted
 * @param {Integer} depth - The number of generations remaining to delete
 * @returns {Instance} parent - The updated subject
 */
Recursive function to prune children from a subject in order to return a
subject hierarchy with the specified depth.

@param {Instance} parent - The subject whose children may be deleted
@param {Integer} depth - The number of generations remaining to delete
@returns {Instance} parent - The updated subject
Recursive function to prune children from a subject in order to return a subject hierarchy with the specified depth . @param { Instance } parent - The subject whose children may be deleted @param { Integer } depth - The number of generations remaining to delete @returns { Instance } parent - The updated subject
function deleteChildren(parent, depth) {
  if (parent.children) {
    if (depth === 1) {
      for (let i = 0; i < parent.children.length; i++) {
        delete parent.children[i].children;
      }
    } else if (depth > 1) {
      for (let i = 0; i < parent.children.length; i++) {
        deleteChildren(parent.children[i], depth - 1);
      }
    }
  }
  return parent;
} 
function deleteChildren ( parent , depth ) { if ( parent . children ) { if ( depth === 1 ) { for ( let i = 0 ; i < parent . children . length ; i ++ ) { delete parent . children [ i ] . children ; } } else if ( depth > 1 ) { for ( let i = 0 ; i < parent . children . length ; i ++ ) { deleteChildren ( parent . children [ i ] , depth - 1 ) ; } } } return parent ; }
Recursive function to prune children from a subject in order to return a
 subject hierarchy with the specified depth.
Recursive function to prune children from a subject in order to return a subject hierarchy with the specified depth .
// deleteChildren