Hide all apps other than specified ones?

I have a script that hides a list of specified apps

set hideApps to {{name:"Finder"}, {name:"Brave Browser"}, {name:"Things"}}

repeat with appToHide in hideApps
	tell application "System Events"
		try
			set visible of process (name of appToHide) to false
		end try
	end tell
end repeat

Now I want a script that hides all apps, other than those specified? I managed to get this one to work below

tell application "System Events" to set visible of every process whose visible is true and name is not "Script Editor" and name is not "Finder" and name is not "Brave Browser" to false

But I was thinking that there would be a better way (more elegant?), listing the apps to exclude in a similar way to my first script instead of using ‘and name is not’ for each app I want to exclude from being hidden?

I wouldn’t call this elegant but it lets you assemble a list and compare that with the open apps.

tell application "System Events"
	set sApp to {"Finder", "Brave Browser", "Things", "Script Editor"}
	set tProc to name of (application processes whose visible is true)
	-- {"Finder", "OmniOutliner", "firefox", "TextEdit", "Script Editor", "Preview"}
	
	-- set hl to {} -- optional to generate list
	repeat with x in tProc
		if sApp does not contain x then
			-- set end of hl to contents of x -- optional to generate list
			set visible of application process x to false
		end if
	end repeat
	-- hl -- to return list
end tell

That’s ‘more elegant’ than mine, thanks a lot!

It feels like a lot of work for something so simple. I would like to just compare the two lists but… that’s how it works. Glad it helps though.