DEV Community

Discussion on: A simple interview question

Collapse
 
isaacdlyman profile image
Isaac Lyman

Change:

if ($element.filter('.js-cool, .js-beans')) {

to

if ($element.filter('.js-cool, .js-beans').length) {

.filter returns an Array, which inherits from Object, and all Objects are truthy in JavaScript.

Collapse
 
jrock2004 profile image
John Costanzo

That is a good way to solve this