PowerShell / PowerShell/PowerShell

Negative Array/String Multiplication (Easy Reverse)

Offen
#26,073 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Issue-Enhancement Needs-Triage WG-Engine WG-NeedsReview
Vorherrschende Sprache
C#
Sterne
55.5k
Forks
8.5k
Ø Merge
1 T. 2 Std.
Gemergte PRs (30 T.)
88

Beschreibung

Summary of the new feature / enhancement

As a PowerShell user and developer, I often want to reverse an array or string.

As a developer who has been using array multiplication to pretty great effect in Turtle, I think it would be extraordinarily geometrically interesting to be able to reverse and repeat a range of steps in a single statement.

It would also provide a shorter way to reverse a list within a single expression (currently, one has to declare the array and then call [Array]::Reverse, which returns nothing). This benefit of simplicity would also extend to strings.

Proposed technical implementation details (optional)

PowerShell already supports array multiplication of a positive number. It should be fairly trivial to support array multiplication of a negative number as well: simply create a reversed copy and then duplicate that array.

Proposed syntax:

1,2,3 * 2 # will produce 1,2,3,1,2,3
1,2,3 * -2 # should produce 3,2,1,3,2,1

This would also open up easy "reverse iteration", without ranges

# Get a list of files in the current folder in reverse order
foreach ($file in @(Get-ChildItem -Path . -File) * -1) {
    $file
}

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue nennt keine Quelldateien, Tests oder Einstiegspunkte. Beginne damit, die vorhandenen positiven Beispiele für Array-Multiplikation zu reproduzieren, und verfolge dann, wo die Multiplikationssemantik behandelt wird. Als erledigt gilt die Aufgabe, wenn negative Multiplikation Arrays und Strings wie gezeigt umkehrt und wiederholt, einschließlich des Verhaltens bei umgekehrter Iteration.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell
Bereich
cli
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.