2 Saved 2 bytes by moving the inner -join operator
source | link

PowerShell, 6161 59 bytes

param($a)(("1"+-join([char[]]-join(2..$a-join'')|sort)),1)[$a-eq1]

Takes input param($a) and then uses it to index into an array with [$a-eq1]. If true, we index the second element and output 1. Otherwise, we concatenate "1" with the joined array created by 1) defining a new range 2..$a that has been itself joined together, 2) casting that as a char-array, and 3) sending it through the Sort-Object cmdlet, all of which is then output.

Edit1 -- Saved 2 bytes by moving the inner -join operator.

PowerShell, 61 bytes

param($a)(("1"+-join([char[]](2..$a-join'')|sort)),1)[$a-eq1]

Takes input param($a) and then uses it to index into an array with [$a-eq1]. If true, we index the second element and output 1. Otherwise, we concatenate "1" with the joined array created by 1) defining a new range 2..$a that has been itself joined together, 2) casting that as a char-array, and 3) sending it through the Sort-Object cmdlet, all of which is then output.

PowerShell, 61 59 bytes

param($a)(("1"+-join([char[]]-join(2..$a)|sort)),1)[$a-eq1]

Takes input param($a) and then uses it to index into an array with [$a-eq1]. If true, we index the second element and output 1. Otherwise, we concatenate "1" with the joined array created by 1) defining a new range 2..$a that has been itself joined together, 2) casting that as a char-array, and 3) sending it through the Sort-Object cmdlet, all of which is then output.

Edit1 -- Saved 2 bytes by moving the inner -join operator.

1
source | link

PowerShell, 61 bytes

param($a)(("1"+-join([char[]](2..$a-join'')|sort)),1)[$a-eq1]

Takes input param($a) and then uses it to index into an array with [$a-eq1]. If true, we index the second element and output 1. Otherwise, we concatenate "1" with the joined array created by 1) defining a new range 2..$a that has been itself joined together, 2) casting that as a char-array, and 3) sending it through the Sort-Object cmdlet, all of which is then output.