I went on an interview and I was asked a question like the one in the codepen. I was asked to fix it as its broken. Just curious how others would answer this one
We're a place where coders share, stay up-to-date and grow their careers.
I went on an interview and I was asked a question like the one in the codepen. I was asked to fix it as its broken. Just curious how others would answer this one
Tefoh -
Laurie -
Jaden Concord -
Eric -
Discussion (4)
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.That is a good way to solve this
We can use a check to see what values the input has at keyboard events. Then if it has empty string we can simply restore the original
font-size
of the mentioned classes.Here is an approach to do so:
Why looping over all objects and filter out then when you can start with a beter filter.