mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Continue to use more ES2015.
This commit is contained in:
@@ -6,12 +6,12 @@
|
|||||||
* @returns {Array} Returns the value-value pairs.
|
* @returns {Array} Returns the value-value pairs.
|
||||||
*/
|
*/
|
||||||
function setToPairs(set) {
|
function setToPairs(set) {
|
||||||
var index = -1,
|
let index = -1;
|
||||||
result = Array(set.size);
|
const result = Array(set.size);
|
||||||
|
|
||||||
set.forEach(function(value) {
|
set.forEach(value =>
|
||||||
result[++index] = [value, value];
|
result[++index] = [value, value]
|
||||||
});
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ import createAggregator from './_createAggregator.js';
|
|||||||
* _.partition(users, 'active');
|
* _.partition(users, 'active');
|
||||||
* // => objects for [['fred'], ['barney', 'pebbles']]
|
* // => objects for [['fred'], ['barney', 'pebbles']]
|
||||||
*/
|
*/
|
||||||
var partition = createAggregator(function(result, value, key) {
|
const partition = createAggregator((result, value, key) =>
|
||||||
result[key ? 0 : 1].push(value);
|
result[key ? 0 : 1].push(value), () => [[], []]);
|
||||||
}, function() { return [[], []]; });
|
|
||||||
|
|
||||||
export default partition;
|
export default partition;
|
||||||
|
|||||||
5
union.js
5
union.js
@@ -18,7 +18,8 @@ import isArrayLikeObject from './isArrayLikeObject.js';
|
|||||||
* _.union([2], [1, 2]);
|
* _.union([2], [1, 2]);
|
||||||
* // => [2, 1]
|
* // => [2, 1]
|
||||||
*/
|
*/
|
||||||
const union = (...arrays) =>
|
function union(...arrays) {
|
||||||
baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
|
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
|
||||||
|
}
|
||||||
|
|
||||||
export default union;
|
export default union;
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import last from './last.js';
|
|||||||
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||||
* // => [{ 'x': 1 }, { 'x': 2 }]
|
* // => [{ 'x': 1 }, { 'x': 2 }]
|
||||||
*/
|
*/
|
||||||
const unionBy = (...arrays) => {
|
function unionBy(...arrays) {
|
||||||
let iteratee = last(arrays);
|
let iteratee = last(arrays);
|
||||||
if (isArrayLikeObject(iteratee)) {
|
if (isArrayLikeObject(iteratee)) {
|
||||||
iteratee = undefined;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2));
|
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2));
|
||||||
};
|
}
|
||||||
|
|
||||||
export default unionBy;
|
export default unionBy;
|
||||||
|
|||||||
5
xor.js
5
xor.js
@@ -20,7 +20,8 @@ import isArrayLikeObject from './isArrayLikeObject.js';
|
|||||||
* _.xor([2, 1], [2, 3]);
|
* _.xor([2, 1], [2, 3]);
|
||||||
* // => [1, 3]
|
* // => [1, 3]
|
||||||
*/
|
*/
|
||||||
const xor = (...arrays) =>
|
function xor(...arrays) {
|
||||||
baseXor(arrayFilter(arrays, isArrayLikeObject));
|
return baseXor(arrayFilter(arrays, isArrayLikeObject));
|
||||||
|
}
|
||||||
|
|
||||||
export default xor;
|
export default xor;
|
||||||
|
|||||||
4
xorBy.js
4
xorBy.js
@@ -27,12 +27,12 @@ import last from './last.js';
|
|||||||
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
|
||||||
* // => [{ 'x': 2 }]
|
* // => [{ 'x': 2 }]
|
||||||
*/
|
*/
|
||||||
const xorBy = (...arrays) => {
|
function xorBy(...arrays) {
|
||||||
let iteratee = last(arrays);
|
let iteratee = last(arrays);
|
||||||
if (isArrayLikeObject(iteratee)) {
|
if (isArrayLikeObject(iteratee)) {
|
||||||
iteratee = undefined;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee, 2));
|
return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee, 2));
|
||||||
};
|
}
|
||||||
|
|
||||||
export default xorBy;
|
export default xorBy;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import baseRest from './_baseRest.js';
|
|
||||||
import unzipWith from './unzipWith.js';
|
import unzipWith from './unzipWith.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,12 +20,12 @@ import unzipWith from './unzipWith.js';
|
|||||||
* });
|
* });
|
||||||
* // => [111, 222]
|
* // => [111, 222]
|
||||||
*/
|
*/
|
||||||
var zipWith = baseRest(function(arrays) {
|
function zipWith(...arrays) {
|
||||||
var length = arrays.length,
|
const length = arrays.length;
|
||||||
iteratee = length > 1 ? arrays[length - 1] : undefined;
|
let iteratee = length > 1 ? arrays[length - 1] : undefined;
|
||||||
|
|
||||||
iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
|
iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
|
||||||
return unzipWith(arrays, iteratee);
|
return unzipWith(arrays, iteratee);
|
||||||
});
|
}
|
||||||
|
|
||||||
export default zipWith;
|
export default zipWith;
|
||||||
|
|||||||
Reference in New Issue
Block a user