The LM317L and resistor act as a current regulator set to 40ma. Current flows from the battery through one pair of LEDs, through the regulator, through the other pair of LEDs, and back to the battery. The capacitor filters out noise on the power supply lines. The LED pairs must be matched so that the current through them is roughly equivalent. Small resistors could be placed in series with each of the four LEDs to improve the balance, but the parts count would go way up.