Improve array functions (#8)

This commit is contained in:
Viktor Szépe
2023-05-23 21:59:54 +02:00
committed by GitHub
parent 3c3b8e6337
commit 74523767af

View File

@@ -237,7 +237,7 @@ _forEachSome_() {
_inArray_() { _inArray_() {
# DESC: # DESC:
# Determine if a value is in an array. Default is case sensitive. # Determine if a regex matches an array element. Default is case sensitive.
# Pass -i flag to ignore case. # Pass -i flag to ignore case.
# ARGS: # ARGS:
# $1 (Required) - Value to search for # $1 (Required) - Value to search for
@@ -291,12 +291,7 @@ _isEmptyArray_() {
# CREDIT: # CREDIT:
# https://github.com/labbots/bash-utility # https://github.com/labbots/bash-utility
declare -a _array=("$@") [ ${#@} -eq 0 ]
if [ ${#_array[@]} -eq 0 ]; then
return 0
else
return 1
fi
} }
_joinArray_() { _joinArray_() {
@@ -449,7 +444,7 @@ _sortArray_() {
# CREDIT: # CREDIT:
# https://github.com/labbots/bash-utility # https://github.com/labbots/bash-utility
[[ $# == 0 ]] && fatal "Missing required argument to ${FUNCNAME[0]}" [[ $# -eq 0 ]] && fatal "Missing required argument to ${FUNCNAME[0]}"
declare -a _array=("$@") declare -a _array=("$@")
declare -a _sortedArray declare -a _sortedArray
mapfile -t _sortedArray < <(printf '%s\n' "${_array[@]}" | sort) mapfile -t _sortedArray < <(printf '%s\n' "${_array[@]}" | sort)