Skip to main content
added 31 characters in body
Source Link

PowerShell, 1313 10 bytes

$f={@($_)*$_}

Usage

PS C:\> 2 | % $f{@($_)*$_}
2
2

And:

PS C:\> 5 | % $f{@($_)*$_}
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> 5 | % $f{@($_)*$_} | ConvertTo-Json -Compress
[5,5,5,5,5]

PowerShell, 13 bytes

$f={@($_)*$_}

Usage

PS C:\> 2 | % $f
2
2

And:

PS C:\> 5 | % $f
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> 5 | % $f | ConvertTo-Json -Compress
[5,5,5,5,5]

PowerShell, 13 10 bytes

{@($_)*$_}

Usage

PS C:\> 2 | % {@($_)*$_}
2
2

And:

PS C:\> 5 | % {@($_)*$_}
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> 5 | % {@($_)*$_} | ConvertTo-Json -Compress
[5,5,5,5,5]
deleted 54 characters in body
Source Link

PowerShell, 813 bytes

$f={@($i$_)*$i*$_}

Usage

PS C:\> $i = 2
PS C:\>| @($i)*$i% $f
2
2

And:

PS C:\> $i = 5
PS C:\>| @($i)*$i% $f
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> $i = 5
PS C:\>| @($i)*$i% $f | ConvertTo-Json -Compress
[5,5,5,5,5]

PowerShell, 8 bytes

@($i)*$i

Usage

PS C:\> $i = 2
PS C:\> @($i)*$i
2
2

And:

PS C:\> $i = 5
PS C:\> @($i)*$i
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> $i = 5
PS C:\> @($i)*$i | ConvertTo-Json -Compress
[5,5,5,5,5]

PowerShell, 13 bytes

$f={@($_)*$_}

Usage

PS C:\> 2 | % $f
2
2

And:

PS C:\> 5 | % $f
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> 5 | % $f | ConvertTo-Json -Compress
[5,5,5,5,5]
Source Link

PowerShell, 8 bytes

@($i)*$i

Usage

PS C:\> $i = 2
PS C:\> @($i)*$i
2
2

And:

PS C:\> $i = 5
PS C:\> @($i)*$i
5
5
5
5
5

By default, PowerShell shows array content one element per line. Running it through the ConvertTo-Json cmdlet shows it in a more familiar form:

PS C:\> $i = 5
PS C:\> @($i)*$i | ConvertTo-Json -Compress
[5,5,5,5,5]