CJam, 6 bytes (full program) / 7 bytes (code block)
Try it online!
This is a full CJam program that reads the input string from standard input and prints the missing letter to standard output. CJam doesn't actually have "methods", which is what the challenge asks for, but the closest thing would probably be an executable code block, like this:
Try it online!
This code block, when evaluated, takes the input as a string (i.e. an array of characters) on the stack, and returns the missing character also on the stack.
Explanation: In the full program,
q reads the input string and places it on the stack.
) then pops off the last character of the input string, and the range operator
, turns it into an array containing all characters with code points below it (including all letters before it in the alphabet). Thus, for example, if the input was
cdfgh, then after
), the stack would contain the strings
cdfg (i.e. the input with the last letter removed) and
... stands for a bunch of characters with ASCII codes below
a (i.e. all characters below the removed last input letter).
The symmetric set difference operator
^ then combines these strings into a single string that contains exactly those characters that appear in one of the strings, but not in both. It preserves the order in which the characters appear in the strings, so for the example input
cdfg, the result after
),^ will be
... again stands for a bunch of characters with ASCII codes below
W= just extracts the last character of this string, which is exactly the missing character
e that we wanted to find (and discards the rest). When the program ends, the CJam interpreter implicitly prints out the contents of the stack.
Bonus: GolfScript, 6 bytes (full program)
Try it online!
It turns out that nearly the same code also works in GolfScript. We save one byte in the full program version due to GolfScript's implicit input, but lose one byte because, unlike CJam's
W, GolfScript doesn't have a handy single-letter variable initialized to -1.
Also, CJam has separate integer and character types (and strings are just arrays containing characters), whereas GolfScript only has a single integer type (and has a special string type that behaves somewhat differently from normal arrays). The result of all this is that, if we want the GolfScript interpreter to print out the actual missing letter instead of its ASCII code number, we need to return a single-character string instead of just the character itself. Fortunately, making that change here just requires replacing the indexing operator
= with the array/string left truncation operator
Of course, thanks to GolfScript's implicit I/O, the code above can also be used as a snippet that reads a string from the stack and returns a single-character string containing the missing letter. Or, rather, any snippet that takes a single string on the stack as an argument, and returns its output as a printable string on the stack, is also a full GolfScript program.