Merge pull request #13887 from tschaub/array-find

Remove find and findIndex from array module
This commit is contained in:
Tim Schaub
2022-07-27 18:09:42 -06:00
committed by GitHub
5 changed files with 11 additions and 108 deletions

View File

@@ -31,7 +31,6 @@ import {
get as getProjection,
transform,
} from '../../../../../src/ol/proj.js';
import {find} from '../../../../../src/ol/array.js';
import {parse} from '../../../../../src/ol/xml.js';
import {remove as removeTransform} from '../../../../../src/ol/proj/transforms.js';
@@ -4256,7 +4255,7 @@ describe('ol.format.KML', function () {
});
it('creates a Point and a MultiPolygon for Alaska', function () {
const alaska = find(features, function (feature) {
const alaska = features.find(function (feature) {
return feature.get('name') === 'Alaska';
});
expect(alaska).to.be.an(Feature);

View File

@@ -3,8 +3,6 @@ import {
binarySearch,
equals,
extend,
find,
findIndex,
isSorted,
linearFindNearest,
numberSafeCompareFunction,
@@ -383,64 +381,6 @@ describe('ol/array.js', function () {
});
});
describe('find', function () {
it('finds numbers in an array', function () {
const a = [0, 1, 2, 3];
const b = find(a, function (val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val > 1;
});
expect(b).to.be(2);
});
it('returns null when an item in an array is not found', function () {
const a = [0, 1, 2, 3];
const b = find(a, function (val, index, a2) {
return val > 100;
});
expect(b).to.be(null);
});
it('finds items in an array-like', function () {
const a = 'abCD';
const b = find(a, function (val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val >= 'A' && val <= 'Z';
});
expect(b).to.be('C');
});
it('returns null when nothing in an array-like is found', function () {
const a = 'abcd';
const b = find(a, function (val, index, a2) {
return val >= 'A' && val <= 'Z';
});
expect(b).to.be(null);
});
});
describe('findIndex', function () {
it('finds index of numbers in an array', function () {
const a = [0, 1, 2, 3];
const b = findIndex(a, function (val, index, a2) {
expect(a).to.equal(a2);
expect(typeof index).to.be('number');
return val > 1;
});
expect(b).to.be(2);
});
it('returns -1 when an item in an array is not found', function () {
const a = [0, 1, 2, 3];
const b = findIndex(a, function (val, index, a2) {
return val > 100;
});
expect(b).to.be(-1);
});
});
describe('isSorted', function () {
it('works with just an array as argument', function () {
expect(isSorted([1, 2, 3])).to.be(true);