Alternative of .includes() in Internet Explorer
Alternative of .includes() in Internet Explorer

For past 2 months I have been actively developing emberjs addon. As we near the release of this add-on, it is time for cross-browser testing(only time developer tests runs his app in Internet Explorer(IE)).
First feature we noticed that was not working in IE was search feature. It depended on .includes() function of js and we realised .includes was not supported in IE.
I had to write substitute of this function. This function basically did 2 things:
- check if element is in array
- check if 1 or more alphabets were in string
Solution I came up with was using indexOf, indexOf works both on string and array, if element is present it returns the position value and -1 otherwise.
My code looked like this:
function includes(container, value) {
var returnValue = false;
var pos = container.indexOf(value);
if (pos >= 0) {
returnValue = true;
}
return returnValue;
}I tested this function with following values:
includes([1,2,3],2) //=> true
includes([1,2,3],'a') //=> false
includes("abc",'a') //=> true
includes("abc",'e') //=> falseSince this worked, I began replacing .includes with my own includes function and then realised in some places I had wanted negative of .includes(). I also wrote another function that would do exactly opposite and named it doesNotInclude. The function looked like this:
function doesNotInclude(container, value) {
var returnValue = false;
var pos = container.indexOf(value);
if (pos < 0) {
returnValue = true;
}
return returnValue;
}I had to support IE 10 and above and these functions are working well for me. Don’t forget to tell me what would be your approach if you were in my place. Happy Coding!
Keep reading

Fix mise GitHub Rate Limit with a Token
mise makes unauthenticated GitHub API calls by default. When you hit the rate limit installing tools, a personal access token (no scopes required) fixes it permanently.

How to solve Deployment Failure-`assets:precompile`
I was trying to deploy rails 6 app on ec2 server using capistrano when precompile failure lead to whole deploymentt failure. I had to uninstall cmdtest and install yarn

How to Sort an Array of Objects in JavaScript
How to Sort an Array of Objects in JavaScript

What did you take away?
Thoughts, pushback, or a story of your own? Drop a reply below — I read every one.
Comments are powered by Disqus. By posting you agree to theirterms.