mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-11 14:14:36 +08:00
Migrating all the new utilities to TypeScript :) I didn't migrate all of the files because: - the original, prototype extending utilities.js - string-utilities.js, which has a bunch of typedefs and is generally a large file. I will migrate that file in a standalone CL as a follow-up to this one. - number-utilities.js, if I migrate this the `UIString` calls don't get picked up by the l10n tooling and the translations get lost. I think I need to update the GRDP tooling to look for `UIString` calls in `.ts` files, which I will follow up on another CL. Bug: 1050549 Change-Id: I53f3129758552b7e9ef8e8abf3608fdf2086c04d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2584262 Reviewed-by: Simon Zünd <szuend@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
25 lines
650 B
TypeScript
25 lines
650 B
TypeScript
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/**
|
|
* @return {boolean} True, if any element got removed.
|
|
*/
|
|
export const removeElement = <T>(array: T[], element: T, firstOnly?: boolean): boolean => {
|
|
let index = array.indexOf(element);
|
|
if (index === -1) {
|
|
return false;
|
|
}
|
|
if (firstOnly) {
|
|
array.splice(index, 1);
|
|
return true;
|
|
}
|
|
for (let i = index + 1, n = array.length; i < n; ++i) {
|
|
if (array[i] !== element) {
|
|
array[index++] = array[i];
|
|
}
|
|
}
|
|
array.length = index;
|
|
return true;
|
|
};
|