Skip to content

Commit 58c944a

Browse files
committed
Added polyfill for Array#find
1 parent cac1e73 commit 58c944a

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

14. Exam - Fortune Cookies/solution-doncho/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ <h1 class="page-header col-md-6">
8282
<script src="js/controllers/my-cookie.js"></script>
8383

8484
<!-- App: Loaders -->
85+
<script src="js/app/polyfills/array.js"></script>
8586
<script src="js/app/data.js"></script>
8687
<script src="js/app/templates.js"></script>
8788
<script src="js/app/json-requester.js"></script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
if (!Array.prototype.find) {
2+
Array.prototype.find = function(predicate) {
3+
if (this === null) {
4+
throw new TypeError('Array.prototype.find called on null or undefined');
5+
}
6+
if (typeof predicate !== 'function') {
7+
throw new TypeError('predicate must be a function');
8+
}
9+
var list = Object(this);
10+
var length = list.length >>> 0;
11+
var thisArg = arguments[1];
12+
var value;
13+
14+
for (var i = 0; i < length; i++) {
15+
value = list[i];
16+
if (predicate.call(thisArg, value, i, list)) {
17+
return value;
18+
}
19+
}
20+
return undefined;
21+
};
22+
}

0 commit comments

Comments
 (0)