diff --git a/CHANGELOG.md b/CHANGELOG.md index 79ae4f9b8b8f..65989e78c741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog ##### Unreleased +- [`Array` find from last](https://github.com/tc39/proposal-array-find-from-last) moved to the stable ES, per June 2022 TC39 meeting + - `Array.prototype.findLast` + - `Array.prototype.findIndex` + - `%TypedArray%.prototype.findLast` + - `%TypedArray%.prototype.findIndex` - Changed the order of operations in `%TypedArray%.prototype.with` following [proposal-change-array-by-copy/86](https://github.com/tc39/proposal-change-array-by-copy/issues/86), per June 2022 TC39 meeting - Fixed a bug in the order of getting flags in `RegExp.prototype.flags` in the actual version of V8 - Fixed property descriptors of some `Math` and `Number` constants diff --git a/README.md b/README.md index cae306c563b4..6b61b30496da 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ queueMicrotask(() => console.log('called as microtask')); - [Relative indexing method](#relative-indexing-method) - [`Array.prototype.includes`](#arrayprototypeincludes) - [`Array.prototype.flat` / `Array.prototype.flatMap`](#arrayprototypeflat--arrayprototypeflatmap) + - [`Array` find from last](#array-find-from-last) - [`Object.values` / `Object.entries`](#objectvalues--objectentries) - [`Object.fromEntries`](#objectfromentries) - [`Object.getOwnPropertyDescriptors`](#objectgetownpropertydescriptors) @@ -126,7 +127,6 @@ queueMicrotask(() => console.log('called as microtask')); - [Well-formed `JSON.stringify`](#well-formed-jsonstringify) - [Stage 3 proposals](#stage-3-proposals) - [`Array` grouping](#array-grouping) - - [`Array` find from last](#array-find-from-last) - [Change `Array` by copy](#change-array-by-copy) - [Stage 2 proposals](#stage-2-proposals) - [`Iterator` helpers](#iterator-helpers) @@ -637,7 +637,7 @@ Error.prototype.toString.call({ message: 1, name: 2 }) === '2: 1'; // => true ``` #### ECMAScript: Array[⬆](#index) -Modules [`es.array.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.from.js), [`es.array.is-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.is-array.js), [`es.array.of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.of.js), [`es.array.copy-within`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.copy-within.js), [`es.array.fill`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.fill.js), [`es.array.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.find.js), [`es.array.find-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.find-index.js), [`es.array.iterator`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.iterator.js), [`es.array.includes`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.includes.js), [`es.array.slice`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.slice.js), [`es.array.join`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.join.js), [`es.array.index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.index-of.js), [`es.array.last-index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.last-index-of.js), [`es.array.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.every.js), [`es.array.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.some.js), [`es.array.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.for-each.js), [`es.array.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.map.js), [`es.array.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.filter.js), [`es.array.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.reduce.js), [`es.array.reduce-right`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.reduce-right.js), [`es.array.reverse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.reverse.js), [`es.array.sort`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.sort.js), [`es.array.flat`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.flat.js), [`es.array.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.flat-map.js), [`es.array.unscopables.flat`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.unscopables.flat.js), [`es.array.unscopables.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.unscopables.flat-map.js), [`es.array.at`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.at.js). +Modules [`es.array.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.from.js), [`es.array.is-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.is-array.js), [`es.array.of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.of.js), [`es.array.copy-within`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.copy-within.js), [`es.array.fill`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.fill.js), [`es.array.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.find.js), [`es.array.find-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.find-index.js), [`es.array.find-last`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.find-last.js), [`es.array.find-last-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.find-last-index.js), [`es.array.iterator`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.iterator.js), [`es.array.includes`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.includes.js), [`es.array.slice`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.slice.js), [`es.array.join`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.join.js), [`es.array.index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.index-of.js), [`es.array.last-index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.last-index-of.js), [`es.array.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.every.js), [`es.array.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.some.js), [`es.array.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.for-each.js), [`es.array.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.map.js), [`es.array.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.filter.js), [`es.array.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.reduce.js), [`es.array.reduce-right`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.reduce-right.js), [`es.array.reverse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.reverse.js), [`es.array.sort`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.sort.js), [`es.array.flat`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.flat.js), [`es.array.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.flat-map.js), [`es.array.unscopables.flat`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.unscopables.flat.js), [`es.array.unscopables.flat-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.unscopables.flat-map.js), [`es.array.at`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array.at.js). ```js class Array { at(index: int): any; @@ -648,7 +648,9 @@ class Array { fill(value: any, start?: number, end?: number): this; filter(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): Array; // with adding support of @@species find(callbackfn: (value: any, index: number, target: any) => boolean), thisArg?: any): any; - findIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): number; + findIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; + findLast(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): any; + findLastIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; flat(depthArg?: number = 1): Array; flatMap(mapFn: (value: any, index: number, target: any) => any, thisArg: any): Array; forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg?: any): void; @@ -692,6 +694,8 @@ core-js(-pure)/es|stable|actual|full/array/fill core-js(-pure)/es|stable|actual|full/array/filter core-js(-pure)/es|stable|actual|full/array/find core-js(-pure)/es|stable|actual|full/array/find-index +core-js(-pure)/es|stable|actual|full/array/find-last +core-js(-pure)/es|stable|actual|full/array/find-last-index core-js(-pure)/es|stable|actual|full/array/flat core-js(-pure)/es|stable|actual|full/array/flat-map core-js(-pure)/es|stable|actual|full/array/for-each @@ -719,6 +723,8 @@ core-js(-pure)/es|stable|actual|full/array/virtual/fill core-js(-pure)/es|stable|actual|full/array/virtual/filter core-js(-pure)/es|stable|actual|full/array/virtual/find core-js(-pure)/es|stable|actual|full/array/virtual/find-index +core-js(-pure)/es|stable|actual|full/array/virtual/find-last +core-js(-pure)/es|stable|actual|full/array/virtual/find-last-index core-js(-pure)/es|stable|actual|full/array/virtual/flat core-js(-pure)/es|stable|actual|full/array/virtual/flat-map core-js(-pure)/es|stable|actual|full/array/virtual/for-each @@ -738,7 +744,7 @@ core-js(-pure)/es|stable|actual|full/array/virtual/sort core-js(-pure)/es|stable|actual|full/array/virtual/splice core-js(-pure)/es|stable|actual|full/array/virtual/values ``` -[*Examples*](https://is.gd/i8mOSe): +[*Examples*](https://tinyurl.com/2br28bgj): ```js Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] Array.from({ 0: 1, 1: 2, 2: 3, length: 3 }); // => [1, 2, 3] @@ -763,8 +769,8 @@ function isOdd(value) { } [4, 8, 15, 16, 23, 42].find(isOdd); // => 15 [4, 8, 15, 16, 23, 42].findIndex(isOdd); // => 2 -[4, 8, 15, 16, 23, 42].find(isNaN); // => undefined -[4, 8, 15, 16, 23, 42].findIndex(isNaN); // => -1 +[1, 2, 3, 4].findLast(isOdd); // => 3 +[1, 2, 3, 4].findLastIndex(isOdd); // => 2 Array(5).fill(42); // => [42, 42, 42, 42, 42] @@ -1567,7 +1573,7 @@ console.log(weakset.has(b)); // => false #### ECMAScript: Typed Arrays[⬆](#index) Implementations and fixes for `ArrayBuffer`, `DataView`, Typed Arrays constructors, static and prototype methods. Typed arrays work only in environments with support descriptors (IE9+), `ArrayBuffer` and `DataView` should work anywhere. -Modules [`es.array-buffer.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array-buffer.constructor.js), [`es.array-buffer.is-view`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array-buffer.is-view.js), [`es.array-buffer.slice`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array-buffer.slice.js), [`es.data-view`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.data-view.js), [`es.typed-array.int8-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.int8-array.js), [`es.typed-array.uint8-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint8-array.js), [`es.typed-array.uint8-clamped-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint8-clamped-array.js), [`es.typed-array.int16-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.int16-array.js), [`es.typed-array.uint16-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint16-array.js), [`es.typed-array.int32-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed.int32-array.js), [`es.typed-array.uint32-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint32-array.js), [`es.typed-array.float32-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.float32-array.js), [`es.typed-array.float64-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.float64-array.js), [`es.typed-array.copy-within`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.copy-within.js), [`es.typed-array.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.every.js), [`es.typed-array.fill`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.fill.js), [`es.typed-array.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.filter.js), [`es.typed-array.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.find.js), [`es.typed-array.find-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.find-index.js), [`es.typed-array.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.for-each.js), [`es.typed-array.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.from.js), [`es.typed-array.includes`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.includes.js), [`es.typed-array.index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.index-of.js), [`es.typed-array.iterator`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.iterator.js), [`es.typed-array.last-index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.last-index-of.js), [`es.typed-array.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.map.js), [`es.typed-array.of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.of.js), [`es.typed-array.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.reduce.js), [`es.typed-array.reduce-right`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.reduce-right.js), [`es.typed-array.reverse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.reverse.js), [`es.typed-array.set`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.set.js), [`es.typed-array.slice`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.slice.js), [`es.typed-array.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.some.js), [`es.typed-array.sort`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.sort.js), [`es.typed-array.subarray`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.subarray.js), [`es.typed-array.to-locale-string`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.to-locale-string.js), [`es.typed-array.to-string`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.to-string.js), [`es.typed-array.at`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.at.js). +Modules [`es.array-buffer.constructor`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array-buffer.constructor.js), [`es.array-buffer.is-view`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array-buffer.is-view.js), [`es.array-buffer.slice`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.array-buffer.slice.js), [`es.data-view`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.data-view.js), [`es.typed-array.int8-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.int8-array.js), [`es.typed-array.uint8-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint8-array.js), [`es.typed-array.uint8-clamped-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint8-clamped-array.js), [`es.typed-array.int16-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.int16-array.js), [`es.typed-array.uint16-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint16-array.js), [`es.typed-array.int32-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed.int32-array.js), [`es.typed-array.uint32-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.uint32-array.js), [`es.typed-array.float32-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.float32-array.js), [`es.typed-array.float64-array`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.float64-array.js), [`es.typed-array.copy-within`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.copy-within.js), [`es.typed-array.every`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.every.js), [`es.typed-array.fill`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.fill.js), [`es.typed-array.filter`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.filter.js), [`es.typed-array.find`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.find.js), [`es.typed-array.find-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.find-index.js), [`es.typed-array.find-last`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.find-last.js), [`es.typed-array.find-last-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.find-last-index.js), [`es.typed-array.for-each`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.for-each.js), [`es.typed-array.from`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.from.js), [`es.typed-array.includes`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.includes.js), [`es.typed-array.index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.index-of.js), [`es.typed-array.iterator`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.iterator.js), [`es.typed-array.last-index-of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.last-index-of.js), [`es.typed-array.map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.map.js), [`es.typed-array.of`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.of.js), [`es.typed-array.reduce`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.reduce.js), [`es.typed-array.reduce-right`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.reduce-right.js), [`es.typed-array.reverse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.reverse.js), [`es.typed-array.set`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.set.js), [`es.typed-array.slice`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.slice.js), [`es.typed-array.some`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.some.js), [`es.typed-array.sort`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.sort.js), [`es.typed-array.subarray`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.subarray.js), [`es.typed-array.to-locale-string`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.to-locale-string.js), [`es.typed-array.to-string`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.to-string.js), [`es.typed-array.at`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.typed-array.at.js). ```js class ArrayBuffer { constructor(length: any): ArrayBuffer; @@ -1622,7 +1628,9 @@ class %TypedArray% { fill(value: number, start?: number, end?: number): this; filter(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): %TypedArray%; find(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean), thisArg?: any): any; - findIndex(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): number; + findIndex(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; + findLast(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): any; + findLastIndex(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; forEach(callbackfn: (value: number, index: number, target: %TypedArray%) => void, thisArg?: any): void; includes(searchElement: any, from?: number): boolean; indexOf(searchElement: any, from?: number): number; @@ -1678,6 +1686,8 @@ core-js/es|stable|actual|full/typed-array/fill core-js/es|stable|actual|full/typed-array/filter core-js/es|stable|actual|full/typed-array/find core-js/es|stable|actual|full/typed-array/find-index +core-js/es|stable|actual|full/typed-array/find-last +core-js/es|stable|actual|full/typed-array/find-last-index core-js/es|stable|actual|full/typed-array/for-each core-js/es|stable|actual|full/typed-array/from core-js/es|stable|actual|full/typed-array/includes @@ -1882,6 +1892,22 @@ class Array { ``` core-js/proposals/array-flat-map ``` +##### [Array find from last](https://github.com/tc39/proposal-array-find-from-last)[⬆](#index) +```js +class Array { + findLast(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): any; + findLastIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; +} + +class %TypedArray% { + findLast(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): any; + findLastIndex(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; +} +``` +[*CommonJS entry points:*](#commonjs-api) +``` +core-js/proposals/array-find-from-last +``` ##### [`Object.values` / `Object.entries`](https://github.com/tc39/proposal-object-values-entries)[⬆](#index) ```js class Object { @@ -2092,32 +2118,6 @@ const map = [1, 2, 3, 4, 5].groupByToMap(it => it % 2); map.get(1); // => [1, 3, 5] map.get(0); // => [2, 4] ```` -##### [Array find from last](https://github.com/tc39/proposal-array-find-from-last)[⬆](#index) -Modules [`esnext.array.find-last`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.find-last.js), [`esnext.array.find-last-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.find-last-index.js), [`esnext.typed-array.find-last`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.find-last.js) and [`esnext.typed-array.find-last-index`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.find-last-index.js). -```js -class Array { - findLast(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): any; - findLastIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; -} - -class %TypedArray% { - findLast(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): any; - findLastIndex(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; -} -``` -[*CommonJS entry points:*](#commonjs-api) -``` -core-js/proposals/array-find-from-last -core-js(-pure)/actual|full(/virtual)/array/find-last -core-js(-pure)/actual|full(/virtual)/array/find-last-index -core-js/actual|full/typed-array/find-last -core-js/actual|full/typed-array/find-last-index -``` -[*Examples*](https://is.gd/GVqNFY): -```js -[1, 2, 3, 4].findLast(it => it % 2); // => 3 -[1, 2, 3, 4].findLastIndex(it => it % 2); // => 2 -```` ##### [Change `Array` by copy](https://github.com/tc39/proposal-change-array-by-copy)[⬆](#index) Modules [`esnext.array.to-reversed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-reversed.js), [`esnext.array.to-sorted`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-sorted.js), [`esnext.array.to-spliced`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-spliced.js), [`esnext.array.with`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.with.js), [`esnext.typed-array.to-reversed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-reversed.js), [`esnext.typed-array.to-sorted`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-sorted.js), [`esnext.typed-array.to-spliced`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-spliced.js), [`esnext.typed-array.with`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.with.js). ```js diff --git a/packages/core-js-compat/README.md b/packages/core-js-compat/README.md index ebb2ab61c7b4..9aea4433710d 100644 --- a/packages/core-js-compat/README.md +++ b/packages/core-js-compat/README.md @@ -27,12 +27,14 @@ console.log(targets); 'es.error.cause': { ios: '14.5-14.8', samsung: '16.0' }, 'es.aggregate-error.cause': { ios: '14.5-14.8', samsung: '16.0' }, 'es.array.at': { ios: '14.5-14.8' }, + 'es.array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, + 'es.array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'es.object.has-own': { ios: '14.5-14.8', samsung: '16.0' }, 'es.string.at-alternative': { ios: '14.5-14.8' }, 'es.typed-array.at': { ios: '14.5-14.8' }, + 'es.typed-array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, + 'es.typed-array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'es.typed-array.set': { samsung: '16.0' }, - 'esnext.array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, - 'esnext.array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.array.group-by': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.array.group-by-to-map': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.array.to-reversed': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, @@ -40,8 +42,6 @@ console.log(targets); 'esnext.array.to-spliced': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.array.unique-by': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.array.with': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, - 'esnext.typed-array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, - 'esnext.typed-array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.typed-array.to-reversed': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.typed-array.to-sorted': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, 'esnext.typed-array.to-spliced': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, diff --git a/packages/core-js-compat/src/data.mjs b/packages/core-js-compat/src/data.mjs index c05f32124e84..09fbf7c8b935 100644 --- a/packages/core-js-compat/src/data.mjs +++ b/packages/core-js-compat/src/data.mjs @@ -187,6 +187,14 @@ export const data = { firefox: '48', safari: '9.0', }, + 'es.array.find-last': { + chrome: '97', + safari: '15.4', + }, + 'es.array.find-last-index': { + chrome: '97', + safari: '15.4', + }, 'es.array.flat': { chrome: '69', firefox: '62', @@ -1421,6 +1429,14 @@ export const data = { firefox: '37', safari: '10.0', }, + 'es.typed-array.find-last': { + chrome: '97', + safari: '15.4', + }, + 'es.typed-array.find-last-index': { + chrome: '97', + safari: '15.4', + }, 'es.typed-array.for-each': { chrome: '45', edge: '13', @@ -1571,14 +1587,10 @@ export const data = { }, 'esnext.array.filter-reject': { }, - 'esnext.array.find-last': { - chrome: '97', - safari: '15.4', - }, - 'esnext.array.find-last-index': { - chrome: '97', - safari: '15.4', - }, + // TODO: Remove from `core-js@4` + 'esnext.array.find-last': null, + // TODO: Remove from `core-js@4` + 'esnext.array.find-last-index': null, 'esnext.array.group-by': { }, 'esnext.array.group-by-to-map': { @@ -1877,14 +1889,10 @@ export const data = { }, 'esnext.typed-array.filter-reject': { }, - 'esnext.typed-array.find-last': { - chrome: '97', - safari: '15.4', - }, - 'esnext.typed-array.find-last-index': { - chrome: '97', - safari: '15.4', - }, + // TODO: Remove from `core-js@4` + 'esnext.typed-array.find-last': null, + // TODO: Remove from `core-js@4` + 'esnext.typed-array.find-last-index': null, // TODO: Remove from `core-js@4` 'esnext.typed-array.group-by': { }, @@ -2076,6 +2084,8 @@ export const renamed = new Map([ ['es.weak-map', 'es.weak-map.constructor'], ['es.weak-set', 'es.weak-set.constructor'], ['esnext.array.at', 'es.array.at'], + ['esnext.array.find-last', 'es.array.find-last'], + ['esnext.array.find-last-index', 'es.array.find-last-index'], ['esnext.aggregate-error', 'es.aggregate-error'], ['esnext.global-this', 'es.global-this'], ['esnext.object.has-own', 'es.object.has-own'], @@ -2084,6 +2094,8 @@ export const renamed = new Map([ ['esnext.string.match-all', 'es.string.match-all'], ['esnext.string.replace-all', 'es.string.replace-all'], ['esnext.typed-array.at', 'es.typed-array.at'], + ['esnext.typed-array.find-last', 'es.typed-array.find-last'], + ['esnext.typed-array.find-last-index', 'es.typed-array.find-last-index'], ['web.url', 'web.url.constructor'], ['web.url-search-params', 'web.url-search-params.constructor'], ]); diff --git a/packages/core-js-compat/src/modules-by-versions.mjs b/packages/core-js-compat/src/modules-by-versions.mjs index 9d27f0fab9d2..4cf8d66874af 100644 --- a/packages/core-js-compat/src/modules-by-versions.mjs +++ b/packages/core-js-compat/src/modules-by-versions.mjs @@ -139,4 +139,10 @@ export default { 'web.atob', 'web.btoa', ], + 3.23: [ + 'es.array.find-last', + 'es.array.find-last-index', + 'es.typed-array.find-last', + 'es.typed-array.find-last-index', + ], }; diff --git a/packages/core-js-pure/override/modules/es.typed-array.find-last-index.js b/packages/core-js-pure/override/modules/es.typed-array.find-last-index.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/core-js-pure/override/modules/es.typed-array.find-last-index.js @@ -0,0 +1 @@ +// empty diff --git a/packages/core-js-pure/override/modules/es.typed-array.find-last.js b/packages/core-js-pure/override/modules/es.typed-array.find-last.js new file mode 100644 index 000000000000..8b1a393741c9 --- /dev/null +++ b/packages/core-js-pure/override/modules/es.typed-array.find-last.js @@ -0,0 +1 @@ +// empty diff --git a/packages/core-js/actual/array/find-last-index.js b/packages/core-js/actual/array/find-last-index.js index 70ba3a234fe6..9091b73c8766 100644 --- a/packages/core-js/actual/array/find-last-index.js +++ b/packages/core-js/actual/array/find-last-index.js @@ -1,4 +1,4 @@ require('../../modules/esnext.array.find-last-index'); -var entryUnbind = require('../../internals/entry-unbind'); +var parent = require('../../stable/array/find-last-index'); -module.exports = entryUnbind('Array', 'findLastIndex'); +module.exports = parent; diff --git a/packages/core-js/actual/array/find-last.js b/packages/core-js/actual/array/find-last.js index 9d10c47d7d8d..871aa55ca01c 100644 --- a/packages/core-js/actual/array/find-last.js +++ b/packages/core-js/actual/array/find-last.js @@ -1,4 +1,4 @@ require('../../modules/esnext.array.find-last'); -var entryUnbind = require('../../internals/entry-unbind'); +var parent = require('../../stable/array/find-last'); -module.exports = entryUnbind('Array', 'findLast'); +module.exports = parent; diff --git a/packages/core-js/actual/array/virtual/find-last-index.js b/packages/core-js/actual/array/virtual/find-last-index.js index 748cf5f2c9ae..bf0ede3ff3be 100644 --- a/packages/core-js/actual/array/virtual/find-last-index.js +++ b/packages/core-js/actual/array/virtual/find-last-index.js @@ -1,4 +1,4 @@ require('../../../modules/esnext.array.find-last-index'); -var entryVirtual = require('../../../internals/entry-virtual'); +var parent = require('../../../stable/array/virtual/find-last-index'); -module.exports = entryVirtual('Array').findLastIndex; +module.exports = parent; diff --git a/packages/core-js/actual/array/virtual/find-last.js b/packages/core-js/actual/array/virtual/find-last.js index ab4f4ef6329c..75e4673010be 100644 --- a/packages/core-js/actual/array/virtual/find-last.js +++ b/packages/core-js/actual/array/virtual/find-last.js @@ -1,4 +1,4 @@ require('../../../modules/esnext.array.find-last'); -var entryVirtual = require('../../../internals/entry-virtual'); +var parent = require('../../../stable/array/virtual/find-last'); -module.exports = entryVirtual('Array').findLast; +module.exports = parent; diff --git a/packages/core-js/actual/typed-array/find-last-index.js b/packages/core-js/actual/typed-array/find-last-index.js index 096a3a3fe85a..397540062ee2 100644 --- a/packages/core-js/actual/typed-array/find-last-index.js +++ b/packages/core-js/actual/typed-array/find-last-index.js @@ -1 +1,4 @@ require('../../modules/esnext.typed-array.find-last-index'); +var parent = require('../../stable/typed-array/find-last-index'); + +module.exports = parent; diff --git a/packages/core-js/actual/typed-array/find-last.js b/packages/core-js/actual/typed-array/find-last.js index af9a272e2efa..fbf1a90d5d90 100644 --- a/packages/core-js/actual/typed-array/find-last.js +++ b/packages/core-js/actual/typed-array/find-last.js @@ -1 +1,4 @@ require('../../modules/esnext.typed-array.find-last'); +var parent = require('../../stable/typed-array/find-last'); + +module.exports = parent; diff --git a/packages/core-js/es/array/find-last-index.js b/packages/core-js/es/array/find-last-index.js new file mode 100644 index 000000000000..69ce74c6d3ad --- /dev/null +++ b/packages/core-js/es/array/find-last-index.js @@ -0,0 +1,4 @@ +require('../../modules/es.array.find-last-index'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'findLastIndex'); diff --git a/packages/core-js/es/array/find-last.js b/packages/core-js/es/array/find-last.js new file mode 100644 index 000000000000..5ac2c97b620a --- /dev/null +++ b/packages/core-js/es/array/find-last.js @@ -0,0 +1,4 @@ +require('../../modules/es.array.find-last'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'findLast'); diff --git a/packages/core-js/es/array/index.js b/packages/core-js/es/array/index.js index a17fb1381ca2..668f4da0f367 100644 --- a/packages/core-js/es/array/index.js +++ b/packages/core-js/es/array/index.js @@ -9,6 +9,8 @@ require('../../modules/es.array.fill'); require('../../modules/es.array.filter'); require('../../modules/es.array.find'); require('../../modules/es.array.find-index'); +require('../../modules/es.array.find-last'); +require('../../modules/es.array.find-last-index'); require('../../modules/es.array.flat'); require('../../modules/es.array.flat-map'); require('../../modules/es.array.for-each'); diff --git a/packages/core-js/es/array/virtual/find-last-index.js b/packages/core-js/es/array/virtual/find-last-index.js new file mode 100644 index 000000000000..cee260e6e176 --- /dev/null +++ b/packages/core-js/es/array/virtual/find-last-index.js @@ -0,0 +1,4 @@ +require('../../../modules/es.array.find-last-index'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').findLastIndex; diff --git a/packages/core-js/es/array/virtual/find-last.js b/packages/core-js/es/array/virtual/find-last.js new file mode 100644 index 000000000000..bd0c4f97d2e3 --- /dev/null +++ b/packages/core-js/es/array/virtual/find-last.js @@ -0,0 +1,4 @@ +require('../../../modules/es.array.find-last'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').findLast; diff --git a/packages/core-js/es/array/virtual/index.js b/packages/core-js/es/array/virtual/index.js index 8daf331c713c..1ed5fd3a4685 100644 --- a/packages/core-js/es/array/virtual/index.js +++ b/packages/core-js/es/array/virtual/index.js @@ -6,6 +6,8 @@ require('../../../modules/es.array.fill'); require('../../../modules/es.array.filter'); require('../../../modules/es.array.find'); require('../../../modules/es.array.find-index'); +require('../../../modules/es.array.find-last'); +require('../../../modules/es.array.find-last-index'); require('../../../modules/es.array.flat'); require('../../../modules/es.array.flat-map'); require('../../../modules/es.array.for-each'); diff --git a/packages/core-js/es/instance/find-last-index.js b/packages/core-js/es/instance/find-last-index.js new file mode 100644 index 000000000000..6d3a28bc0325 --- /dev/null +++ b/packages/core-js/es/instance/find-last-index.js @@ -0,0 +1,9 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../array/virtual/find-last-index'); + +var ArrayPrototype = Array.prototype; + +module.exports = function (it) { + var own = it.findLastIndex; + return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.findLastIndex) ? method : own; +}; diff --git a/packages/core-js/es/instance/find-last.js b/packages/core-js/es/instance/find-last.js new file mode 100644 index 000000000000..aa0474c287b2 --- /dev/null +++ b/packages/core-js/es/instance/find-last.js @@ -0,0 +1,9 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../array/virtual/find-last'); + +var ArrayPrototype = Array.prototype; + +module.exports = function (it) { + var own = it.findLast; + return it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.findLast) ? method : own; +}; diff --git a/packages/core-js/es/typed-array/find-last-index.js b/packages/core-js/es/typed-array/find-last-index.js new file mode 100644 index 000000000000..cc0f224f8158 --- /dev/null +++ b/packages/core-js/es/typed-array/find-last-index.js @@ -0,0 +1 @@ +require('../../modules/es.typed-array.find-last-index'); diff --git a/packages/core-js/es/typed-array/find-last.js b/packages/core-js/es/typed-array/find-last.js new file mode 100644 index 000000000000..4a0654aa977d --- /dev/null +++ b/packages/core-js/es/typed-array/find-last.js @@ -0,0 +1 @@ +require('../../modules/es.typed-array.find-last'); diff --git a/packages/core-js/es/typed-array/methods.js b/packages/core-js/es/typed-array/methods.js index 5bef54460a07..bce275ccea7e 100644 --- a/packages/core-js/es/typed-array/methods.js +++ b/packages/core-js/es/typed-array/methods.js @@ -9,6 +9,8 @@ require('../../modules/es.typed-array.fill'); require('../../modules/es.typed-array.filter'); require('../../modules/es.typed-array.find'); require('../../modules/es.typed-array.find-index'); +require('../../modules/es.typed-array.find-last'); +require('../../modules/es.typed-array.find-last-index'); require('../../modules/es.typed-array.for-each'); require('../../modules/es.typed-array.includes'); require('../../modules/es.typed-array.index-of'); diff --git a/packages/core-js/modules/es.array.find-last-index.js b/packages/core-js/modules/es.array.find-last-index.js new file mode 100644 index 000000000000..3a4809fb816e --- /dev/null +++ b/packages/core-js/modules/es.array.find-last-index.js @@ -0,0 +1,14 @@ +'use strict'; +var $ = require('../internals/export'); +var $findLastIndex = require('../internals/array-iteration-from-last').findLastIndex; +var addToUnscopables = require('../internals/add-to-unscopables'); + +// `Array.prototype.findLastIndex` method +// https://github.com/tc39/proposal-array-find-from-last +$({ target: 'Array', proto: true }, { + findLastIndex: function findLastIndex(callbackfn /* , that = undefined */) { + return $findLastIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + } +}); + +addToUnscopables('findLastIndex'); diff --git a/packages/core-js/modules/es.array.find-last.js b/packages/core-js/modules/es.array.find-last.js new file mode 100644 index 000000000000..aa21a4664fc5 --- /dev/null +++ b/packages/core-js/modules/es.array.find-last.js @@ -0,0 +1,14 @@ +'use strict'; +var $ = require('../internals/export'); +var $findLast = require('../internals/array-iteration-from-last').findLast; +var addToUnscopables = require('../internals/add-to-unscopables'); + +// `Array.prototype.findLast` method +// https://github.com/tc39/proposal-array-find-from-last +$({ target: 'Array', proto: true }, { + findLast: function findLast(callbackfn /* , that = undefined */) { + return $findLast(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); + } +}); + +addToUnscopables('findLast'); diff --git a/packages/core-js/modules/es.typed-array.find-last-index.js b/packages/core-js/modules/es.typed-array.find-last-index.js new file mode 100644 index 000000000000..03e89d334594 --- /dev/null +++ b/packages/core-js/modules/es.typed-array.find-last-index.js @@ -0,0 +1,12 @@ +'use strict'; +var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); +var $findLastIndex = require('../internals/array-iteration-from-last').findLastIndex; + +var aTypedArray = ArrayBufferViewCore.aTypedArray; +var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; + +// `%TypedArray%.prototype.findLastIndex` method +// https://github.com/tc39/proposal-array-find-from-last +exportTypedArrayMethod('findLastIndex', function findLastIndex(predicate /* , thisArg */) { + return $findLastIndex(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined); +}); diff --git a/packages/core-js/modules/es.typed-array.find-last.js b/packages/core-js/modules/es.typed-array.find-last.js new file mode 100644 index 000000000000..8d0a8ef99da6 --- /dev/null +++ b/packages/core-js/modules/es.typed-array.find-last.js @@ -0,0 +1,12 @@ +'use strict'; +var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); +var $findLast = require('../internals/array-iteration-from-last').findLast; + +var aTypedArray = ArrayBufferViewCore.aTypedArray; +var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; + +// `%TypedArray%.prototype.findLast` method +// https://github.com/tc39/proposal-array-find-from-last +exportTypedArrayMethod('findLast', function findLast(predicate /* , thisArg */) { + return $findLast(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined); +}); diff --git a/packages/core-js/modules/esnext.array.find-last-index.js b/packages/core-js/modules/esnext.array.find-last-index.js index 3a4809fb816e..5e2fb45579ba 100644 --- a/packages/core-js/modules/esnext.array.find-last-index.js +++ b/packages/core-js/modules/esnext.array.find-last-index.js @@ -1,14 +1,2 @@ -'use strict'; -var $ = require('../internals/export'); -var $findLastIndex = require('../internals/array-iteration-from-last').findLastIndex; -var addToUnscopables = require('../internals/add-to-unscopables'); - -// `Array.prototype.findLastIndex` method -// https://github.com/tc39/proposal-array-find-from-last -$({ target: 'Array', proto: true }, { - findLastIndex: function findLastIndex(callbackfn /* , that = undefined */) { - return $findLastIndex(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); - } -}); - -addToUnscopables('findLastIndex'); +// TODO: Remove from `core-js@4` +require('../modules/es.array.find-last-index'); diff --git a/packages/core-js/modules/esnext.array.find-last.js b/packages/core-js/modules/esnext.array.find-last.js index aa21a4664fc5..784f4df0010b 100644 --- a/packages/core-js/modules/esnext.array.find-last.js +++ b/packages/core-js/modules/esnext.array.find-last.js @@ -1,14 +1,2 @@ -'use strict'; -var $ = require('../internals/export'); -var $findLast = require('../internals/array-iteration-from-last').findLast; -var addToUnscopables = require('../internals/add-to-unscopables'); - -// `Array.prototype.findLast` method -// https://github.com/tc39/proposal-array-find-from-last -$({ target: 'Array', proto: true }, { - findLast: function findLast(callbackfn /* , that = undefined */) { - return $findLast(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); - } -}); - -addToUnscopables('findLast'); +// TODO: Remove from `core-js@4` +require('../modules/es.array.find-last'); diff --git a/packages/core-js/modules/esnext.typed-array.find-last-index.js b/packages/core-js/modules/esnext.typed-array.find-last-index.js index 03e89d334594..92bd57392a57 100644 --- a/packages/core-js/modules/esnext.typed-array.find-last-index.js +++ b/packages/core-js/modules/esnext.typed-array.find-last-index.js @@ -1,12 +1,2 @@ -'use strict'; -var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); -var $findLastIndex = require('../internals/array-iteration-from-last').findLastIndex; - -var aTypedArray = ArrayBufferViewCore.aTypedArray; -var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; - -// `%TypedArray%.prototype.findLastIndex` method -// https://github.com/tc39/proposal-array-find-from-last -exportTypedArrayMethod('findLastIndex', function findLastIndex(predicate /* , thisArg */) { - return $findLastIndex(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined); -}); +// TODO: Remove from `core-js@4` +require('../modules/es.typed-array.find-last-index'); diff --git a/packages/core-js/modules/esnext.typed-array.find-last.js b/packages/core-js/modules/esnext.typed-array.find-last.js index 8d0a8ef99da6..55015ca777d2 100644 --- a/packages/core-js/modules/esnext.typed-array.find-last.js +++ b/packages/core-js/modules/esnext.typed-array.find-last.js @@ -1,12 +1,2 @@ -'use strict'; -var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); -var $findLast = require('../internals/array-iteration-from-last').findLast; - -var aTypedArray = ArrayBufferViewCore.aTypedArray; -var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; - -// `%TypedArray%.prototype.findLast` method -// https://github.com/tc39/proposal-array-find-from-last -exportTypedArrayMethod('findLast', function findLast(predicate /* , thisArg */) { - return $findLast(aTypedArray(this), predicate, arguments.length > 1 ? arguments[1] : undefined); -}); +// TODO: Remove from `core-js@4` +require('../modules/es.typed-array.find-last'); diff --git a/packages/core-js/stable/array/find-last-index.js b/packages/core-js/stable/array/find-last-index.js new file mode 100644 index 000000000000..bff726a482b3 --- /dev/null +++ b/packages/core-js/stable/array/find-last-index.js @@ -0,0 +1 @@ +module.exports = require('../../es/array/find-last-index'); diff --git a/packages/core-js/stable/array/find-last.js b/packages/core-js/stable/array/find-last.js new file mode 100644 index 000000000000..2f10e120c610 --- /dev/null +++ b/packages/core-js/stable/array/find-last.js @@ -0,0 +1 @@ +module.exports = require('../../es/array/find-last'); diff --git a/packages/core-js/stable/array/virtual/find-last-index.js b/packages/core-js/stable/array/virtual/find-last-index.js new file mode 100644 index 000000000000..b84a1fffc296 --- /dev/null +++ b/packages/core-js/stable/array/virtual/find-last-index.js @@ -0,0 +1 @@ +module.exports = require('../../../es/array/virtual/find-last-index'); diff --git a/packages/core-js/stable/array/virtual/find-last.js b/packages/core-js/stable/array/virtual/find-last.js new file mode 100644 index 000000000000..d8a7975590d9 --- /dev/null +++ b/packages/core-js/stable/array/virtual/find-last.js @@ -0,0 +1 @@ +module.exports = require('../../../es/array/virtual/find-last'); diff --git a/packages/core-js/stable/instance/find-last-index.js b/packages/core-js/stable/instance/find-last-index.js new file mode 100644 index 000000000000..81219fed9b30 --- /dev/null +++ b/packages/core-js/stable/instance/find-last-index.js @@ -0,0 +1,3 @@ +var parent = require('../../es/instance/find-last-index'); + +module.exports = parent; diff --git a/packages/core-js/stable/instance/find-last.js b/packages/core-js/stable/instance/find-last.js new file mode 100644 index 000000000000..9ff20d231c90 --- /dev/null +++ b/packages/core-js/stable/instance/find-last.js @@ -0,0 +1,3 @@ +var parent = require('../../es/instance/find-last'); + +module.exports = parent; diff --git a/packages/core-js/stable/typed-array/find-last-index.js b/packages/core-js/stable/typed-array/find-last-index.js new file mode 100644 index 000000000000..d19b35d02f37 --- /dev/null +++ b/packages/core-js/stable/typed-array/find-last-index.js @@ -0,0 +1 @@ +module.exports = require('../../es/typed-array/find-last-index'); diff --git a/packages/core-js/stable/typed-array/find-last.js b/packages/core-js/stable/typed-array/find-last.js new file mode 100644 index 000000000000..59a82b2ac2ab --- /dev/null +++ b/packages/core-js/stable/typed-array/find-last.js @@ -0,0 +1 @@ +module.exports = require('../../es/typed-array/find-last'); diff --git a/tests/commonjs.mjs b/tests/commonjs.mjs index b65ef5c4d59e..f2e0ad546939 100644 --- a/tests/commonjs.mjs +++ b/tests/commonjs.mjs @@ -83,6 +83,8 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(load(NS, 'array/fill')(Array(5), 2)[0] === 2); ok(load(NS, 'array/find')([2, 3, 4], it => it % 2) === 3); ok(load(NS, 'array/find-index')([2, 3, 4], it => it % 2) === 1); + ok(load(NS, 'array/find-last')([1, 2, 3], it => it % 2) === 3); + ok(load(NS, 'array/find-last-index')([1, 2, 3], it => it % 2) === 2); ok('next' in load(NS, 'array/keys')([])); ok('next' in load(NS, 'array/values')([])); ok(load(NS, 'array/includes')([1, 2, 3], 2)); @@ -110,6 +112,8 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(load(NS, 'array/virtual/fill').call(Array(5), 2)[0] === 2); ok(load(NS, 'array/virtual/find').call([2, 3, 4], it => it % 2) === 3); ok(load(NS, 'array/virtual/find-index').call([2, 3, 4], it => it % 2) === 1); + ok(load(NS, 'array/virtual/find-last').call([1, 2, 3], it => it % 2) === 3); + ok(load(NS, 'array/virtual/find-last-index').call([1, 2, 3], it => it % 2) === 2); ok('next' in load(NS, 'array/virtual/keys').call([])); ok('next' in load(NS, 'array/virtual/values').call([])); ok(load(NS, 'array/virtual/includes').call([1, 2, 3], 2)); @@ -365,17 +369,29 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(typeof instanceFilter([]) == 'function'); ok(instanceFilter([]).call([1, 2, 3], it => it % 2).length === 2); + const instanceFind = load(NS, 'instance/find'); + ok(typeof instanceFind == 'function'); + ok(instanceFind({}) === undefined); + ok(typeof instanceFind([]) == 'function'); + ok(instanceFind([]).call([1, 2, 3], it => it % 2) === 1); + const instanceFindIndex = load(NS, 'instance/find-index'); ok(typeof instanceFindIndex == 'function'); ok(instanceFindIndex({}) === undefined); ok(typeof instanceFindIndex([]) == 'function'); ok(instanceFindIndex([]).call([1, 2, 3], it => it % 2) === 0); - const instanceFind = load(NS, 'instance/find'); - ok(typeof instanceFind == 'function'); - ok(instanceFind({}) === undefined); - ok(typeof instanceFind([]) == 'function'); - ok(instanceFind([]).call([1, 2, 3], it => it % 2) === 1); + const instanceFindLast = load(NS, 'instance/find-last'); + ok(typeof instanceFindLast == 'function'); + ok(instanceFindLast({}) === undefined); + ok(typeof instanceFindLast([]) == 'function'); + ok(instanceFindLast([]).call([1, 2, 3], it => it % 2) === 3); + + const instanceFindLastIndex = load(NS, 'instance/find-last-index'); + ok(typeof instanceFindLastIndex == 'function'); + ok(instanceFindLastIndex({}) === undefined); + ok(typeof instanceFindLastIndex([]) == 'function'); + ok(instanceFindLastIndex([]).call([1, 2, 3], it => it % 2) === 2); const instanceFlags = load(NS, 'instance/flags'); ok(typeof instanceFlags == 'function'); @@ -563,16 +579,12 @@ for (PATH of ['core-js-pure', 'core-js']) { } for (const NS of ['actual', 'full', 'features']) { - ok(load(NS, 'array/find-last')([1, 2, 3], it => it % 2) === 3); - ok(load(NS, 'array/find-last-index')([1, 2, 3], it => it % 2) === 2); ok(typeof load(NS, 'array/group-by') == 'function'); ok(typeof load(NS, 'array/group-by-to-map') == 'function'); ok(load(NS, 'array/with')([1, 2, 3], 1, 4)); ok(load(NS, 'array/to-reversed')([1, 2, 3])[0] === 3); ok(load(NS, 'array/to-sorted')([3, 2, 1])[0] === 1); ok(load(NS, 'array/to-spliced')([3, 2, 1], 1, 1, 4, 5).length === 4); - ok(load(NS, 'array/virtual/find-last').call([1, 2, 3], it => it % 2) === 3); - ok(load(NS, 'array/virtual/find-last-index').call([1, 2, 3], it => it % 2) === 2); ok(typeof load(NS, 'array/virtual/group-by') == 'function'); ok(typeof load(NS, 'array/virtual/group-by-to-map') == 'function'); ok(load(NS, 'array/virtual/with').call([1, 2, 3], 1, 4)); @@ -580,18 +592,6 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(load(NS, 'array/virtual/to-sorted').call([3, 2, 1])[0] === 1); ok(load(NS, 'array/virtual/to-spliced').call([3, 2, 1], 1, 1, 4, 5).length === 4); - const instanceFindLastIndex = load(NS, 'instance/find-last-index'); - ok(typeof instanceFindLastIndex == 'function'); - ok(instanceFindLastIndex({}) === undefined); - ok(typeof instanceFindLastIndex([]) == 'function'); - ok(instanceFindLastIndex([]).call([1, 2, 3], it => it % 2) === 2); - - const instanceFindLast = load(NS, 'instance/find-last'); - ok(typeof instanceFindLast == 'function'); - ok(instanceFindLast({}) === undefined); - ok(typeof instanceFindLast([]) == 'function'); - ok(instanceFindLast([]).call([1, 2, 3], it => it % 2) === 3); - const instanceGroupBy = load(NS, 'instance/group-by'); ok(typeof instanceGroupBy == 'function'); ok(instanceGroupBy({}) === undefined); @@ -916,6 +916,8 @@ for (const NS of ['es', 'stable', 'actual', 'full', 'features']) { load(NS, 'typed-array/filter'); load(NS, 'typed-array/find'); load(NS, 'typed-array/find-index'); + load(NS, 'typed-array/find-last'); + load(NS, 'typed-array/find-last-index'); load(NS, 'typed-array/for-each'); load(NS, 'typed-array/from'); load(NS, 'typed-array/includes'); @@ -942,8 +944,6 @@ for (const NS of ['es', 'stable', 'actual', 'full', 'features']) { } for (const NS of ['actual', 'full', 'features']) { - load(NS, 'typed-array/find-last'); - load(NS, 'typed-array/find-last-index'); load(NS, 'typed-array/to-reversed'); load(NS, 'typed-array/to-sorted'); load(NS, 'typed-array/to-spliced'); diff --git a/tests/compat/tests.js b/tests/compat/tests.js index 4fd55421c0e1..ed3507f00d9e 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -350,6 +350,12 @@ GLOBAL.tests = { Array(1).findIndex(function () { return SKIPS_HOLES = false; }); return !SKIPS_HOLES && Array.prototype[Symbol.unscopables].findIndex; }, + 'es.array.find-last': function () { + return [].findLast; + }, + 'es.array.find-last-index': function () { + return [].findLastIndex; + }, 'es.array.flat': function () { return Array.prototype.flat; }, @@ -1213,6 +1219,12 @@ GLOBAL.tests = { 'es.typed-array.find-index': [ARRAY_BUFFER_VIEWS_SUPPORT, function () { return Int8Array.prototype.findIndex; }], + 'es.typed-array.find-last': function () { + return Int8Array.prototype.findLast; + }, + 'es.typed-array.find-last-index': function () { + return Int8Array.prototype.findLastIndex; + }, 'es.typed-array.for-each': [ARRAY_BUFFER_VIEWS_SUPPORT, function () { return Int8Array.prototype.forEach; }], @@ -1360,12 +1372,6 @@ GLOBAL.tests = { 'esnext.array.filter-reject': function () { return [].filterReject; }, - 'esnext.array.find-last': function () { - return [].findLast; - }, - 'esnext.array.find-last-index': function () { - return [].findLastIndex; - }, 'esnext.array.group-by': function () { try { // https://bugs.webkit.org/show_bug.cgi?id=236541 @@ -1685,12 +1691,6 @@ GLOBAL.tests = { 'esnext.typed-array.filter-reject': function () { return Int8Array.prototype.filterReject; }, - 'esnext.typed-array.find-last': function () { - return Int8Array.prototype.findLast; - }, - 'esnext.typed-array.find-last-index': function () { - return Int8Array.prototype.findLastIndex; - }, 'esnext.typed-array.to-reversed': function () { return Int8Array.prototype.toReversed; }, diff --git a/tests/pure/esnext.array.find-last-index.js b/tests/pure/es.array.find-last-index.js similarity index 94% rename from tests/pure/esnext.array.find-last-index.js rename to tests/pure/es.array.find-last-index.js index b28b092f9f81..fd17720879d5 100644 --- a/tests/pure/esnext.array.find-last-index.js +++ b/tests/pure/es.array.find-last-index.js @@ -1,6 +1,6 @@ import { STRICT } from '../helpers/constants'; -import findLastIndex from 'core-js-pure/actual/array/find-last-index'; +import findLastIndex from 'core-js-pure/es/array/find-last-index'; QUnit.test('Array#findLastIndex', assert => { assert.isFunction(findLastIndex); diff --git a/tests/pure/esnext.array.find-last.js b/tests/pure/es.array.find-last.js similarity index 94% rename from tests/pure/esnext.array.find-last.js rename to tests/pure/es.array.find-last.js index dd87c231df6c..4c8524f20e68 100644 --- a/tests/pure/esnext.array.find-last.js +++ b/tests/pure/es.array.find-last.js @@ -1,6 +1,6 @@ import { STRICT } from '../helpers/constants'; -import findLast from 'core-js-pure/actual/array/find-last'; +import findLast from 'core-js-pure/es/array/find-last'; QUnit.test('Array#findLast', assert => { assert.isFunction(findLast); diff --git a/tests/tests/esnext.array.find-last-index.js b/tests/tests/es.array.find-last-index.js similarity index 100% rename from tests/tests/esnext.array.find-last-index.js rename to tests/tests/es.array.find-last-index.js diff --git a/tests/tests/esnext.array.find-last.js b/tests/tests/es.array.find-last.js similarity index 100% rename from tests/tests/esnext.array.find-last.js rename to tests/tests/es.array.find-last.js