mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Remove semicolons.
This commit is contained in:
44
transform.js
44
transform.js
@@ -1,13 +1,13 @@
|
||||
import arrayEach from './.internal/arrayEach.js';
|
||||
import baseCreate from './.internal/baseCreate.js';
|
||||
import baseForOwn from './.internal/baseForOwn.js';
|
||||
import isBuffer from './isBuffer.js';
|
||||
import isFunction from './isFunction.js';
|
||||
import isObject from './isObject.js';
|
||||
import isTypedArray from './isTypedArray.js';
|
||||
import arrayEach from './.internal/arrayEach.js'
|
||||
import baseCreate from './.internal/baseCreate.js'
|
||||
import baseForOwn from './.internal/baseForOwn.js'
|
||||
import isBuffer from './isBuffer.js'
|
||||
import isFunction from './isFunction.js'
|
||||
import isObject from './isObject.js'
|
||||
import isTypedArray from './isTypedArray.js'
|
||||
|
||||
/**
|
||||
* An alternative to `reduce`; this method transforms `object` to a new
|
||||
* An alternative to `reduce` this method transforms `object` to a new
|
||||
* `accumulator` object which is the result of running each of its own
|
||||
* enumerable string keyed properties thru `iteratee`, with each invocation
|
||||
* potentially mutating the `accumulator` object. If `accumulator` is not
|
||||
@@ -25,35 +25,35 @@ import isTypedArray from './isTypedArray.js';
|
||||
* @example
|
||||
*
|
||||
* transform([2, 3, 4], (result, n) => {
|
||||
* result.push(n *= n);
|
||||
* return n % 2 == 0;
|
||||
* }, []);
|
||||
* result.push(n *= n)
|
||||
* return n % 2 == 0
|
||||
* }, [])
|
||||
* // => [4, 9]
|
||||
*
|
||||
* transform({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => {
|
||||
* (result[value] || (result[value] = [])).push(key);
|
||||
* }, {});
|
||||
* (result[value] || (result[value] = [])).push(key)
|
||||
* }, {})
|
||||
* // => { '1': ['a', 'c'], '2': ['b'] }
|
||||
*/
|
||||
function transform(object, iteratee, accumulator) {
|
||||
const isArr = Array.isArray(object);
|
||||
const isArrLike = isArr || isBuffer(object) || isTypedArray(object);
|
||||
const isArr = Array.isArray(object)
|
||||
const isArrLike = isArr || isBuffer(object) || isTypedArray(object)
|
||||
|
||||
if (accumulator == null) {
|
||||
const Ctor = object && object.constructor;
|
||||
const Ctor = object && object.constructor
|
||||
if (isArrLike) {
|
||||
accumulator = isArr ? new Ctor : [];
|
||||
accumulator = isArr ? new Ctor : []
|
||||
}
|
||||
else if (isObject(object)) {
|
||||
accumulator = isFunction(Ctor) ? baseCreate(Object.getPrototypeOf(object)) : {};
|
||||
accumulator = isFunction(Ctor) ? baseCreate(Object.getPrototypeOf(object)) : {}
|
||||
}
|
||||
else {
|
||||
accumulator = {};
|
||||
accumulator = {}
|
||||
}
|
||||
}
|
||||
(isArrLike ? arrayEach : baseForOwn)(object, (value, index, object) =>
|
||||
iteratee(accumulator, value, index, object));
|
||||
return accumulator;
|
||||
iteratee(accumulator, value, index, object))
|
||||
return accumulator
|
||||
}
|
||||
|
||||
export default transform;
|
||||
export default transform
|
||||
|
||||
Reference in New Issue
Block a user