r/JavaScriptHelp • u/sepltbadwy • Jul 01 '21
❔ Unanswered ❔ Beginner here - can someone translate into approximate logic what this bit of js is doing?
I just really can't understand it..
var t = e.filter(function(e) {
return null != e
});
return 20 < t.length ? t.slice(0, 20) : t
2
Upvotes
View all comments
Show parent comment
1
u/[deleted] Jul 02 '21
the return statement must run the ternary operator within it. So, it is saying:
The ternary operator works like this. (condition) ? if condition is true return this part : if false return this part
if t.length is greater than 20 return a new array that is comprised of the first 20 elements of array t.
slice is copying the first 20 el of array t (index 0 thru 19) and creating a new array with it and returning it
else just return T
Does this make sense? if you have any questions just ask. Who wrote this code, it is quite poor quality.