MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / flatten

Function flatten

public/javascripts/underscore.js:490–507  ·  view source on GitHub ↗
(input, shallow, strict, startIndex)

Source from the content-addressed store, hash-verified

488
489 // Internal implementation of a recursive `flatten` function.
490 var flatten = function(input, shallow, strict, startIndex) {
491 var output = [], idx = 0;
492 for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
493 var value = input[i];
494 if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
495 //flatten current level of array or arguments object
496 if (!shallow) value = flatten(value, shallow, strict);
497 var j = 0, len = value.length;
498 output.length += len;
499 while (j < len) {
500 output[idx++] = value[j++];
501 }
502 } else if (!strict) {
503 output[idx++] = value;
504 }
505 }
506 return output;
507 };
508
509 // Flatten out an array, either recursively (by default), or just one level.
510 _.flatten = function(array, shallow) {

Callers 1

underscore.jsFile · 0.70

Calls 1

isArrayLikeFunction · 0.70

Tested by

no test coverage detected