List generation function from an array of array(level, text)
15106
protected function generate_list($listitems) {
        $list = "";
        $current_depth = 1;
        $next_depth = 1;
        $liststack = array();
        for ($lc = 0; $lc < count($listitems) && $next_depth; $lc++) {
            $cli = $listitems[$lc];
            $nli = isset($listitems[$lc + 1]) ? $listitems[$lc + 1] : null;

            $text = $cli[1];

            $current_depth = $next_depth;
            $next_depth = $nli ? $nli[0] : null;

            if ($next_depth == $current_depth || $next_depth == null) {
                $list .= parser_utils::h('li', $text) . "\n";
            } else if ($next_depth > $current_depth) {
                $next_depth = $current_depth + 1;

                $list .= "<li>" . $text . "\n";
                $list .= "<" . $nli[2] . ">" . "\n";
                $liststack[] = $nli[2];
            } else {
                $list .= parser_utils::h('li', $text) . "\n";

                for ($lv = $next_depth; $lv < $current_depth; $lv++) {
                    $type = array_pop($liststack);
                    $list .= "</$type>" . "\n" . "</li>" . "\n";
                }
            }
        }

        for ($lv = 1; $lv < $current_depth; $lv++) {
            $type = array_pop($liststack);
            $list .= "</$type>" . "\n" . "</li>" . "\n";
        }

        return $list;
    }
1238930
function() {
	  var level       = 0;
	  var levels      = [0,0,0,0,0,0,0];
	  var hLevelText  = '';
	  var prependText = '';
	  var prevLevel   = 0;
	  var n           = 0;
	  self.children('*:header:visible').each(function(index, heading) {
		log('Processing heading %o', heading);
		level = parseInt(heading.tagName.substring(1));
		if (config.min_level <= level && level <= config.max_level) {
		  n++;
		  levels[level]++;
		  for (var l = 1; l <= level; l++) {
			hLevelText += levels[l] > 0 ? levels[l] + config.number_separator : '';
		  }
		  levels[level + 1] = 0;
		  hLevelText = hLevelText.substring(0, hLevelText.length - 1);
		  prependText = hLevelText;
		  if (config.generate_toc || config.add_anchors) {
			if (config.generate_toc) {
			  var link = '<a href="#h' + hLevelText + '">' +jQuery('<span/>').text(jQuery(this).text()).html() + '</a>';
			  var elem = "\n"+'<li>' + hLevelText + (config.number_suffix ? config.number_suffix : '') + ' ' + link;
			  if (level < prevLevel) {
				log(hLevelText + ', unnesting because:' + level + '<' + prevLevel);
				var unnest = '';
				while (level < prevLevel) {
				  unnest += '</ul>';
				  prevLevel--;
				}
				toc += unnest + elem + '</li>';
			  } else if (level > prevLevel) {
				log(hLevelText + ', nesting because:' + level + '>' + prevLevel);
				toc += '<ul>' + elem;
			  } else {
				log(hLevelText + ', same level (' + level + ')');
				toc += elem;
			  }
			}
			prependText = '<span id="h' + hLevelText + '"></span>' + hLevelText;
		  }
		  if (config.number_suffix) {
			prependText += config.number_suffix;
		  }
		  jQuery(this).prepend(prependText + ' ');
		  prependText = hLevelText = '';
		  prevLevel = level;
		}
	  });

	  if (config.generate_toc) {
		if (config.toc_title) {
		  toc = '<h4>' + config.toc_title + '</h4>' + toc;
		}
		if (n == 0) {
		  toc += config.toc_none ? '<p>' + config.toc_none + '</p>' : '';
		}
		jQuery(config.toc_elem ? config.toc_elem : 'body').append(toc);
	  }

	  processed = true;
	}
567062
function arrayToList(array) {
  if(isArray(array)) {
    return List.fromArray(array)
  }
  else if(isFunction(array)) {
    return function(x) {
      const g = array(x)

      if(!isArray(g)) {
        throw new TypeError('arrayToList: Array returning function required')
      }

      return List.fromArray(g)
    }
  }

  throw new TypeError('arrayToList: Array or Array returning function required')
}
293071
function listToPair(list = []) {
  const size = list.length;
  const pairList = [];
  list.forEach((name, idx) => {
    for (let i = idx; i < size; i++) {
      pairList.push([name, list[i]]);
    }
  });
  return pairList;
}
132055
def array_indented(level, l, quote_char='\'', comma_after=False):
    # type: (int, List[str], str, bool) -> str
    
    out = "[\n"
    for x in l:
        out += (((level+1) * 4) * " ") + '{}{}{}'.format(quote_char, x, quote_char) + ",\n"
    out += ((level * 4) * " ") + "]"
    if comma_after:
        out += ","
    return out
750032
def generate_ul(self, a_list):
        '''  '''
        return len(a_list) > 0 and (isinstance(a_list[0], Rule) or
                                    isinstance(a_list[0], LabelDecl))
1012743
function(lines) {
		let output = [];
		let newlineCount = 0;
		for (let i = 0; i < lines.length; i++) {
			const line = lines[i];
			if (!line.trim()) {
				newlineCount++;
			} else {
				newlineCount = 0;
			}

			if (newlineCount >= 2) continue;

			output.push(line);
		}
		return output;
	}
254767
function strArrayToObj (array) {
  return array && array.reduce(function(o, v) {
      o[v] = true;
      return o;
    }, {});
}
560388
def process_repeated_list(self, key, lst, level):
        
        lines = []

        for v in lst:
            k = key.upper()
            v = self.quoter.add_quotes(v)
            lines.append(self.__format_line(self.whitespace(level, 1), k, v))

        return lines
1295826
function stringifyArray(array, replacer, space, indent) {
  let childIndent = space ? (indent + space) : undefined;
  let str = space ? '[\n' : '[';

  // check for circular reference
  if (isCircular(array)) {
    return stringifyCircular(array, replacer, space, indent);
  }

  // add this array to the stack
  const stackIndex = stack.length;
  stack[stackIndex] = array;

  for (let i = 0; i < array.length; i++) {
    let key = i + '';
    let item = (typeof replacer === 'function')
        ? replacer.call(array, key, array[i])
        : array[i];

    if (space) {
      str += childIndent;
    }

    if (typeof item !== 'undefined' && typeof item !== 'function') {
      path[stackIndex] = key;
      str += stringifyValue(item, replacer, space, childIndent);
    }
    else {
      str += 'null'
    }

    if (i < array.length - 1) {
      str += space ? ',\n' : ',';
    }
  }

  // remove current entry from the stack
  stack.length = stackIndex;
  path.length = stackIndex;

  str += space ? ('\n' + indent + ']') : ']';
  return str;
}
431428
function arrayFunction(item, index) {
      return function(data, cb) {
        if (iterator.length === 2) {
          iterator(item, cb);
        } else if (iterator.length === 3) {
          iterator(item, index, cb);
        } else {
          iterator(item, index, data, cb);
        }
      };
    }
587101
def array_indented(level: int, l: List[str], quote_char='\'', comma_after=False) -> str:
    
    out = "[\n"
    for x in l:
        out += (((level+1) * 4) * " ") + '{}{}{}'.format(quote_char, x, quote_char) + ",\n"
    out += ((level * 4) * " ") + "]"
    if comma_after:
        out += ","
    return out
800295
function(array, n) {
      var ret = [];
      var sz = _.size(array);

      if (n <= 0) return [];
      if (n === 1) return array;

      for(var index = 0; index < sz; index += n) {
        ret.push(array[index]);
      }

      return ret;
    }
138753
function(input, shallow, strict, startIndex) {
                var output = [], idx = 0;
                for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
                  var value = input[i];
                  if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
                    //flatten current level of array or arguments object
                    if (!shallow) value = flatten(value, shallow, strict);
                    var j = 0, len = value.length;
                    output.length += len;
                    while (j < len) {
                      output[idx++] = value[j++];
                    }
                  } else if (!strict) {
                    output[idx++] = value;
                  }
                }
                return output;
              }
388464
def pad(lines, delim):
	
	"""
	Populates text into chunks. If the delim was & then
	['12 & 344', '344 & 8', '8 & 88'] would be stored in chunks as
	[['12', '344', '8'], ['344', '8', '88']]
	"""
	chunks = []
	for i in range(len(lines)):
		line = lines[i]
		sections = line.split(delim)
		for j in range(len(sections)):
			if len(chunks) <= j:
				chunks.append([])
			chunks[j].append(sections[j])

	"""
	Calculates & Stores the max length of chunks
	"""
	max_lengths = []
	for i in range(len(chunks)):
		_max = max([len(j) for j in chunks[i]])
		max_lengths.append(_max)

	"""
	Pads the children of chunks according to the chunk's max length" \
	"""
	for i in range(len(chunks)):
		for j in range(len(chunks[i])):
			chunks[i][j] += (max_lengths[i] - len(chunks[i][j])) * ' '
	new_lines = ['' for i in range(len(lines))]

	for i in range(len(chunks)):
		for j in range(len(chunks[i])):
			new_lines[j] += chunks[i][j]
	return new_lines
1309540
static  function toTree($list,$parent_field = 'parent_id',$id_field='id',$children_field='children') {
        $map = self::groupBy($list);
        $data=[];
        foreach ($list as $item) {
            $item->text=$item->name;
            if(is_object($item)){
                if(!$item->$parent_field){
                    $item->$children_field=$map[$item->$id_field];
                    $data[]=$item;
                }
            }
        }
        return $data;
    }
1346542
def from_array(cls, arr):
        """"""
        return cls().with_columns([(f, arr[f]) for f in arr.dtype.names])