From c500de403d06cd9d11a742868ecd59d64e96207f Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Sat, 6 Jan 2018 16:41:42 +0530 Subject: [PATCH] Update --- snippets/indexOfAll.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/snippets/indexOfAll.md b/snippets/indexOfAll.md index f542e1e31..fb636aecf 100644 --- a/snippets/indexOfAll.md +++ b/snippets/indexOfAll.md @@ -4,10 +4,11 @@ Returns an array of indexes at which the `val` occurs in `arr`. If it occurs onl ``` js const indexOfAll = (arr, val) => { - let indexes = [], i; - arr.forEach((el,i) => {if(el === val) indexes.push(i)}) - return indexes.length === 0 ? [-1] : indexes -} + const indices = []; + arr.forEach((el, i) => el === val && indices.push(i)) + return indices.length ? indices : [-1]; +}; + ``` ``` js indexOfAll([1,2,3],1); // [0]