Solution for pangram

This commit is contained in:
David Doblas Jiménez 2023-04-28 18:25:06 +02:00
parent fcae51f2c2
commit 56fc641009

View File

@ -1,24 +1,17 @@
#!/usr/bin/env bash
# The following comments should help you get started:
# - Bash is flexible. You may use functions or write a "raw" script.
#
# - Complex code can be made easier to read by breaking it up
# into functions, however this is sometimes overkill in bash.
#
# - You can find links about good style and other resources
# for Bash in './README.md'. It came with this exercise.
#
# Example:
# # other functions here
# # ...
# # ...
#
# main () {
# # your main function code here
# }
#
# # call main with all of the positional arguments
# main "$@"
#
# *** PLEASE REMOVE THESE COMMENTS BEFORE SUBMITTING YOUR SOLUTION ***
# Convert to lowercase and remove non-alphabetic characters
sentence_alpha="$(echo "$1" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alpha:]')"
# `fold -w1` splits the string into individual characters, one per line
# `sort -u` remove duplicates
# `tr` delete newline characters
sentence_unique="$(echo -n "${sentence_alpha}" | fold -w1 | sort -u | tr -d '\n')"
# Check if the unique alphabets count is 26 (total number of English alphabets)
if [[ ${#sentence_unique} == 26 ]]; then
echo "true"
else
echo "false"
fi