Skip to content

Commit

Permalink
use a constant as a error message
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Feb 6, 2024
1 parent b36ca26 commit e7f6af0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core-js/internals/array-reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ var lengthOfArrayLike = require('../internals/length-of-array-like');

var $TypeError = TypeError;

var REDUCE_EMPTY = 'Reduce of empty array with no initial value';

// `Array.prototype.{ reduce, reduceRight }` methods implementation
var createMethod = function (IS_RIGHT) {
return function (that, callbackfn, argumentsLength, memo) {
var O = toObject(that);
var self = IndexedObject(O);
var length = lengthOfArrayLike(O);
aCallable(callbackfn);
if (length === 0 && argumentsLength < 2) throw new $TypeError('Reduce of empty array with no initial value');
if (length === 0 && argumentsLength < 2) throw new $TypeError(REDUCE_EMPTY);
var index = IS_RIGHT ? length - 1 : 0;
var i = IS_RIGHT ? -1 : 1;
if (argumentsLength < 2) while (true) {
Expand All @@ -24,7 +26,7 @@ var createMethod = function (IS_RIGHT) {
}
index += i;
if (IS_RIGHT ? index < 0 : length <= index) {
throw new $TypeError('Reduce of empty array with no initial value');
throw new $TypeError(REDUCE_EMPTY);
}
}
for (;IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {
Expand Down

0 comments on commit e7f6af0

Please sign in to comment.