Pangram checker: Difference between revisions

Content added Content deleted
(→‎{{header|AppleScript}}: Updated primitives)
(Refactored code)
Line 1,423: Line 1,423:
=={{header|Julia}}==
=={{header|Julia}}==
<tt>makepangramchecker</tt> creates a function to test for pangramity based upon the contents of its input string, allowing one to create arbitrary pangram checkers.
<tt>makepangramchecker</tt> creates a function to test for pangramity based upon the contents of its input string, allowing one to create arbitrary pangram checkers.
<lang Julia>
<lang Julia>function makepangramchecker(alphabet)
alphabet = Set(uppercase.(alphabet))
function makepangramchecker{T<:String}(a::T)
function ispangram(s)
abet = sort(unique(split(uppercase(a), "")))
alen = length(abet)
lengthcheck = length(s) ≥ length(alphabet)
return lengthcheck && all(c in uppercase(s) for c in alphabet)
function ispangram{T<:String}(s::T)
alen <= length(s) || return false
ps = filter(c->(c in abet), unique(split(uppercase(s), "")))
return length(ps) == alen
end
end
return ispangram
end
end


tests = ["Pack my box with five dozen liquor jugs.",
const tests = ["Pack my box with five dozen liquor jugs.",
"The quick brown fox jumps over a lazy dog.",
"The quick brown fox jumps over a lazy dog.",
"The quick brown fox jumps\u2323over the lazy dog.",
"The quick brown fox jumps\u2323over the lazy dog.",
"The five boxing wizards jump quickly.",
"The five boxing wizards jump quickly.",
"This sentence contains A-Z but not the whole alphabet."]
"This sentence contains A-Z but not the whole alphabet."]


isenglishpang = makepangramchecker("abcdefghijklmnopqrstuvwxyz")
is_english_pangram = makepangramchecker('a':'z')


for s in tests
for s in tests
print("The sentence \"", s, "\" is ")
println("The sentence \"", s, "\" is ", is_english_pangram(s) ? "" : "not ", "a pangram.")
end</lang>
if !isenglishpang(s)
print("not ")
end
println("a pangram.")
end
</lang>


{{out}}
{{out}}