Skip to content

feat: $array indexing improvements#2651

Merged
ebiggz merged 1 commit intocrowbartools:v5from
phroggster:better_array_indexing
Aug 1, 2024
Merged

feat: $array indexing improvements#2651
ebiggz merged 1 commit intocrowbartools:v5from
phroggster:better_array_indexing

Conversation

@phroggster
Copy link
Collaborator

@phroggster phroggster commented Jul 31, 2024

Description of the Change

  • $arrayRemove
    • Add "first" option as an index argument, with examples.
    • Shortcut single-item arrays into returning [].
  • $arrayElement
    • Add numerous invocation examples.
    • Add "first" and "last" as index arguments.
    • POSSIBLY BREAKING: use Array.isArray to validate that it's an array.
      • This likely BREAKS ArrayBuffer, Uin8Array, DataView, Blob, etc. types.

Applicable Issues

N/A

Testing

Tested a command using the following in a Log Message, which all output appropriate text, g-i being null:

a) $arrayElement["[1,2,3]", 0]
b) $arrayElement["[1,2,3]", first]
c) $arrayElement["[1,2,3]", last]
d) $arrayRemove["[1,2,3]", 0]
e) $arrayRemove["[1,2,3]", first]
f) $arrayRemove["[1,2,3]", last]

g) $arrayElement["[1,2,3]", 4]
h) $arrayElement["[1,2,3]", four]
i) $arrayElement["[1,2,3]", -1]

j) $arrayRemove["[1,2,3]", 4]
k) $arrayRemove["[1,2,3]", four]
l) $arrayRemove["[1,2,3]", -1]
m) $arrayRemove["[1,2,3]", -2]

Screenshots

array-variable-examples

- `$arrayRemove`
  - Add "first" option as an index argument, with examples.
  - Shortcut single-item arrays into returning [].
- `$arrayElement`
  - Add numerous invocation examples.
  - Add "first" and "last" as index arguments.
  - POSSIBLY BREAKING: use Array.isArray to validate that it's an array.
    - This likely *BREAKS* ArrayBuffer, Uin8Array, DataView, Blob, etc. types.
@phroggster phroggster requested a review from ebiggz as a code owner July 31, 2024 11:54
@phroggster
Copy link
Collaborator Author

The behavior of negative indexing in arrayElement... I'm open for suggestions. It presently returns undefined, but should probably be enhanced for reversed indexing, or similar.

@ebiggz ebiggz merged commit b8f4547 into crowbartools:v5 Aug 1, 2024
@phroggster phroggster deleted the better_array_indexing branch August 1, 2024 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments