PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/compact.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 31 lines | 14 code | 2 blank | 15 comment | 3 complexity | 74065cf32642e0c979818e5254ff3914 MD5 | raw file
 1/**
 2 * Creates an array with all falsey values removed. The values `false`, `null`,
 3 * `0`, `""`, `undefined`, and `NaN` are falsey.
 4 *
 5 * @static
 6 * @memberOf _
 7 * @since 0.1.0
 8 * @category Array
 9 * @param {Array} array The array to compact.
10 * @returns {Array} Returns the new array of filtered values.
11 * @example
12 *
13 * _.compact([0, 1, false, 2, '', 3]);
14 * // => [1, 2, 3]
15 */
16function compact(array) {
17  var index = -1,
18      length = array == null ? 0 : array.length,
19      resIndex = 0,
20      result = [];
21
22  while (++index < length) {
23    var value = array[index];
24    if (value) {
25      result[resIndex++] = value;
26    }
27  }
28  return result;
29}
30
31module.exports = compact;