mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Use more for-of
This commit is contained in:
@@ -7,12 +7,13 @@
|
|||||||
* @param {Function} comparator The comparator invoked per element.
|
* @param {Function} comparator The comparator invoked per element.
|
||||||
* @returns {boolean} Returns `true` if `target` is found, else `false`.
|
* @returns {boolean} Returns `true` if `target` is found, else `false`.
|
||||||
*/
|
*/
|
||||||
function arrayIncludesWith(array, value, comparator) {
|
function arrayIncludesWith(array, target, comparator) {
|
||||||
let index = -1
|
if (array == null) {
|
||||||
const length = array == null ? 0 : array.length
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
while (++index < length) {
|
for (const value of array) {
|
||||||
if (comparator(value, array[index])) {
|
if (comparator(target, value)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ import isFlattenable from './isFlattenable.js'
|
|||||||
* @returns {Array} Returns the new flattened array.
|
* @returns {Array} Returns the new flattened array.
|
||||||
*/
|
*/
|
||||||
function baseFlatten(array, depth, predicate, isStrict, result) {
|
function baseFlatten(array, depth, predicate, isStrict, result) {
|
||||||
let index = -1
|
|
||||||
const { length } = array
|
|
||||||
|
|
||||||
predicate || (predicate = isFlattenable)
|
predicate || (predicate = isFlattenable)
|
||||||
result || (result = [])
|
result || (result = [])
|
||||||
|
|
||||||
while (++index < length) {
|
if (array == null) {
|
||||||
const value = array[index]
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const value of array) {
|
||||||
if (depth > 0 && predicate(value)) {
|
if (depth > 0 && predicate(value)) {
|
||||||
if (depth > 1) {
|
if (depth > 1) {
|
||||||
// Recursively flatten arrays (susceptible to call stack limits).
|
// Recursively flatten arrays (susceptible to call stack limits).
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
* // => [1, 2, 3]
|
* // => [1, 2, 3]
|
||||||
*/
|
*/
|
||||||
function compact(array) {
|
function compact(array) {
|
||||||
let index = -1
|
|
||||||
let resIndex = 0
|
let resIndex = 0
|
||||||
const length = array == null ? 0 : array.length
|
|
||||||
const result = []
|
const result = []
|
||||||
|
|
||||||
while (++index < length) {
|
if (array == null) {
|
||||||
const value = array[index]
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const value of array) {
|
||||||
if (value) {
|
if (value) {
|
||||||
result[resIndex++] = value
|
result[resIndex++] = value
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user