From c5a88ca33786421365c926447391a436c473d1ac Mon Sep 17 00:00:00 2001 From: Juraj Husar Date: Sun, 1 Oct 2017 12:46:26 +0200 Subject: [PATCH] Added ugly ES5 equivalent of findIndex --- features.txt | 2 +- index.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features.txt b/features.txt index 29cd28d..6ad4103 100644 --- a/features.txt +++ b/features.txt @@ -1404,7 +1404,7 @@ New function for finding an element in an array. 6| [ 1, 3, 4, 2 ].|findIndex|(|x =>| x > 3); // 2 5| [ 1, 3, 4, 2 ].|filter|(|function (x) { return| x > 3; })|[0]|; // 4 -5| // no equivalent in ES5 +5| [ 1, 3, 4, 2 ].|map|(|function(x, index) { return| x > 3 |? index : undefined; }).filter(function (x) { return x !== undefined; }|)|[0]|; // 2 String Repeating ---------------- diff --git a/index.html b/index.html index 00fcf5f..7450b38 100644 --- a/index.html +++ b/index.html @@ -1918,8 +1918,8 @@
ECMAScript 5 — syntactic sugar: reduced | traditional
-
[ 1, 3, 4, 2 ].filter(function (x) { return x > 3; })[0]; // 4 -// no equivalent in ES5
+
[ 1, 3, 4, 2 ].filter(function (x) { return x > 3; })[0]; // 4 +[ 1, 3, 4, 2 ].map(function(x, index) { return x > 3 ? index : undefined; }).filter(function (x) { return x !== undefined; })[0]; // 2