This is not a function, because you have the same value appearing twice in your domain.
However, a function need not map every element in its domain set to an element in its range set. A function need not map to every element in its range, either!
For example, $f(x) = 0$ is a function from reals to the reals. But it only ever takes a single value!
A function that hits every value in its range is called onto. Think of onto functions as smearing butter on toast -- you want to make sure every bit of the toast is covered!
Sometimes, however, you want functions to hit each part of the target set exactly once. These functions are called injective. For example, $f(x) = x-1$ is injective, because any value in the range is only hit by a single value of $x$. This is like making sure you have a perfectly thin layer of butter on your toast.
Functions that are both injective and onto are very important functions -- they are called bijections, and they are crucially important in many areas of mathematics.