Hacker News new | ask | show | jobs
by WithTeeth 3742 days ago
Cool idea, but kind of ironic that the example you used produces unnecessarily complicated stack overflow solutions. A JavaScript "contains" function is as simple as:

var contains = function (needle, haystack) { return haystack.indexOf(needle) !== -1 }

2 comments

You should submit this to SO, so that future developers can have it autocompleted in their projects.
Older IEs don't have Array.indexOf(). So you either have to extend the Array prototype or, you know, just implement it in a more compatible way.
> Older IEs don't have Array.indexOf()

IE8 and older to be specific[0]. But, if you're supporting IE8 still you have bigger problems at hand.

Microsoft stopped supporting any version lower than IE11 as of January 12th of this year[1]. So unless all of those older IE machines are accessing an intranet (and only an intranet) their risk of being hit with malware is way higher than average.

For my clients I do a cursory IE9+ review, but if anything lower is a requirement then it's an additional fee to make a site work with it.

In a few months it'll be IE11+ and the same fee structure will apply to anything lower (I'm just waiting for IE10 to wind down a bit).

[0] http://caniuse.com/#search=array.indexof

[1] https://www.microsoft.com/en-us/WindowsForBusiness/End-of-IE...

Or just not support older IEs.

http://browserupdate.org/