From b51a35e0065cfbe95596454125a84fed67e55af9 Mon Sep 17 00:00:00 2001 From: Alexander Lukin Date: Thu, 16 Jun 2016 13:38:25 +0300 Subject: [PATCH] add Array::map polyfill to compatible with es4 --- src/bowser.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/bowser.js b/src/bowser.js index 59f1666..81d1c6c 100644 --- a/src/bowser.js +++ b/src/bowser.js @@ -418,6 +418,23 @@ return version.split(".").length; } + /** + * Array::map polyfill + * @param {Array} arr + * @param {Function} iterator + * @return {Array} + */ + function map(arr, iterator) { + var result = [], i; + if (Array.prototype.map) { + return Array.prototype.map.call(arr, iterator); + } + for (i = 0; i < arr.length; i++) { + result = iterator(arr[i]); + } + return result; + } + /** * Calculate browser version weight * @see http://jsbin.com/vohahaciku/1/edit?js,console