Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ugly ES5 equivalent of findIndex #111

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1918,8 +1918,8 @@
</div>
<div class="arrow"><i class="fa fa-caret-up"></i><i class="fa fa-caret-down"></i></div><div class="js es5">
<div class="title"><b>ECMAScript 5</b> &mdash; syntactic sugar: <span class="style reduced">reduced</span> | <span class="style traditional">traditional</span></div>
<div class="code"><span class="punctuation">[</span> <span class="literal">1</span><span class="punctuation">,</span> <span class="literal">3</span><span class="punctuation">,</span> <span class="literal">4</span><span class="punctuation">,</span> <span class="literal">2</span> <span class="punctuation">]</span><span class="punctuation">.</span><span class="mark">filter</span><span class="punctuation">(</span><span class="mark"><span class="keyword">function</span> <span class="punctuation">(</span>x<span class="punctuation">)</span> <span class="punctuation">{</span> <span class="keyword">return</span></span> x <span class="punctuation">&gt;</span> <span class="literal">3</span><span class="semi">;</span> <span class="punctuation">}</span><span class="punctuation">)</span><span class="mark"><span class="punctuation">[</span><span class="literal">0</span><span class="punctuation">]</span></span><span class="semi">;</span><span class="comment"> // <span class="literal">4</span></span><span class="comment">
// no equivalent <span class="keyword">in</span> ES<span class="literal">5</span></span></div>
<div class="code"><span class="punctuation">[</span> <span class="literal">1</span><span class="punctuation">,</span> <span class="literal">3</span><span class="punctuation">,</span> <span class="literal">4</span><span class="punctuation">,</span> <span class="literal">2</span> <span class="punctuation">]</span><span class="punctuation">.</span><span class="mark">filter</span><span class="punctuation">(</span><span class="mark"><span class="keyword">function</span> <span class="punctuation">(</span>x<span class="punctuation">)</span> <span class="punctuation">{</span> <span class="keyword">return</span></span> x <span class="punctuation">&gt;</span> <span class="literal">3</span><span class="semi">;</span> <span class="punctuation">}</span><span class="punctuation">)</span><span class="mark"><span class="punctuation">[</span><span class="literal">0</span><span class="punctuation">]</span></span><span class="semi">;</span><span class="comment"> // <span class="literal">4</span></span>
<span class="punctuation">[</span> <span class="literal">1</span><span class="punctuation">,</span> <span class="literal">3</span><span class="punctuation">,</span> <span class="literal">4</span><span class="punctuation">,</span> <span class="literal">2</span> <span class="punctuation">]</span><span class="punctuation">.</span><span class="mark">map</span><span class="punctuation">(</span><span class="mark"><span class="keyword">function</span><span class="punctuation">(</span>x<span class="punctuation">,</span> index<span class="punctuation">)</span> <span class="punctuation">{</span> <span class="keyword">return</span></span> x <span class="punctuation">&gt;</span> <span class="literal">3</span> <span class="mark">? index : undefined<span class="semi">;</span> <span class="punctuation">}</span><span class="punctuation">)</span><span class="punctuation">.</span>filter<span class="punctuation">(</span><span class="keyword">function</span> <span class="punctuation">(</span>x<span class="punctuation">)</span> <span class="punctuation">{</span> <span class="keyword">return</span> x !== undefined<span class="semi">;</span> <span class="punctuation">}</span></span><span class="punctuation">)</span><span class="mark"><span class="punctuation">[</span><span class="literal">0</span><span class="punctuation">]</span></span><span class="semi">;</span><span class="comment"> // <span class="literal">2</span></span></div>
<i class="icon fa fa-circle"></i>
<i class="icon fa fa-times-circle"></i>
</div>
Expand Down