Browse Source

feat(array-selector): add solution

DEV-4191-DeepInSystem
nprimo 2 years ago committed by Niccolò Primo
parent
commit
9038c5b3dd
  1. 14
      sh/tests/solutions/array-selector.sh

14
sh/tests/solutions/array-selector.sh

@ -0,0 +1,14 @@
#!/usr/bin/env bash
IFS='
'
COLORS=('red' 'blue' 'green' 'white' 'black')
if [[ ! $1 =~ ^[0-9]+$ ]] || [[ $1 -le 0 ]] || [[ $1 -gt ${#COLORS[@]} ]]; then
echo 'Error'
exit 1
fi
POS=$(($1 - 1))
echo ${COLORS[$POS]}
Loading…
Cancel
Save