I am troubled by the lack of consensus in the stack exchange post . Is it possible to get a definitive clarification.
Does a function need to map every element in the domain to an element in the codomain?
However if you define a function's domain as the set of inputs that have a meaningful output, then yes a function must map all elements in its domain to its codomain.
Also see this pdf they make a distinction between 'input domain' and then just 'domain'.