In the following script, each time you click the button it shows 4 more elements:

Load 4 more elements

I need to change the script so that when all elements are visible and you click again the button, all elements get hidden except of the first 4 elements.

I tried for hours but couldn't find any solution. Could you please help me?