Linear Search in Powershell

Published on 09 July 2025 (Updated: 09 July 2025)

Welcome to the Linear Search in Powershell page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function Show-Usage() {
    Write-Host 'Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")'
    Exit 1
}

function Parse-IntList([string]$Str) {
    @($Str.Split(",") | ForEach-Object { [int]::Parse($_) })
}

function Invoke-LinearSearch([int[]]$arr, [int]$target) {
    $arr.IndexOf($target)
}

if ($args.Length -lt 2 -or -not $args[0]) {
    Show-Usage
}

try {
    $arr = Parse-IntList $args[0]
    $target = [int]::Parse($args[1])
} catch {
    Show-Usage
}

$idx = Invoke-LinearSearch $arr $target
Write-Output (($idx -ge 0) ? "true" : "false")

Linear Search in Powershell was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.