www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit c774b69de8ab4229a621ddbcc84c1156f8578d89
parent ed9d62d98c9713b90b83844ffc2185d071c0ce5b
Author: Ben Alpert <spicyjalapeno@gmail.com>
Date:   Sun, 14 Jul 2013 22:46:00 -0700

Make contains() actually work in IE8

Summary: IE8 doesn't have indexOf on arrays!

Reviewers: emily

Reviewed By: emily

Differential Revision: http://phabricator.khanacademy.org/D3052

Diffstat:
Mutils.js | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/utils.js b/utils.js @@ -1,7 +1,18 @@ -function contains(list, elem) { +function fastContains(list, elem) { return list.indexOf(elem) !== -1; } +function slowContains(list, elem) { + for (var i = 0; i < list.length; i++) { + if (list[i] === elem) { + return true; + } + } + return false; +} + +var contains = Array.prototype.indexOf ? fastContains : slowContains; + module.exports = { contains: contains }