The three major stock indexes in the United States ended the week with gains despite a tech sell-off Friday led by Snap, the company behind the app Snapchat.