This is a simple implementation of the hashcash technique to prevent a user from spamming requests to the server, asking the user a proof of work
The idea is to ask the client to perform a hash operation on a random string increasing the match zero bits each time
You can se more details about the hashcash on wikipedia
You can see this sample running here
For this sample I limit the compare to 20 bits to avoid client browser crash.