Solomon wrote 3000 proverbs and collected other wise sayings; some made it into the book of Proverbs. These chapters are from the collection of the words of the wise. They are a collection of 30 sayings that were in use across the then-known world.
The advice of the wise is to neither rejoice when enemies fall nor fret when they succeed:
24:17-201 Do not rejoice when your enemies fall,
and do not let your heart be glad when they stumble,
or else the Lord will see it and be displeased,
and turn away his anger from them.
Do not fret because of evildoers.
Do not envy the wicked;
for the evil have no future;
the lamp of the wicked will go out.
King David expanded this idea in Psalm 37, telling us not to fret because of the wicked, but rather to:
Psalm 37:3-4 Trust in the Lord, and do good;
so you will live in the land, and enjoy security.
Take delight in the Lord,
and he will give you the desires of your heart.