

A quiz about RegExp.prototype.exec return values and numeric indexes (or indices...
source link: https://miketaylr.com/posts/2014/05/quiz-no-two.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A quiz about RegExp.prototype.exec return values and numeric indexes (or indices or however you people pluralize that word).
01 May 2014
Given the following user agent string ua
and function expression r
,
var ua = "Mozilla/5.0 (Android; Mobile; rv:31.0) Gecko/31.0 Firefox/31.0"
r = function (e) {
if (e.indexOf('android') !== - 1) {
var t = /android (\d)/gi,
n = parseInt(t.exec(e)[1], 10);
return !isNaN(n) && n >= 4
}
return !1
}
What’s the value of parseInt(t.exec(e)[1], 10)
?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Trick question. You get a TypeError
because the [1]th index of null
doesn’t̗̦͇̮͕̾ ̝̠̥̩̞͙̣ͤ̑ͧ̏ͥe̹͉̘̯̎͒̃x̤͑̿i̬ͮ͑̇̎̉s͉̝̩̲̹͒́t̻͍̻̯̗̅ͅ.̩ͧͯ̆̑̇̒
So what do you win for taking this quiz?
If you happen to work for Comedy Central, your prize is now you know why you have a bug!
If you don’t, you can follow this link to entertain yourself with similar bloopers in the wild.
Recommend
-
4
When optimizing code, one thing I’m always looking for is memory layout and access patterns. One such pattern is an arena: Reserve some sufficiently large space to put your objects in, then allocate by incrementing a poi...
-
11
Modeling graphs in Rust using vector indices Apr 6, 2015 After reading nrc’s blog post about graphs, I felt inspired to write u...
-
10
Membership proofs and De Bruijn indicesMembership proofs and De Bruijn indices 2020, Jan 19 by Tesla Ice Zhang {-#
-
7
Paging indices vs Continuation tokens Feb 22, 2010 softwa...
-
7
Basic Data Structure in JavaScript : Arrays (3 Part Series) In this episode of the series, let's learn How to Modify Array Data with Indices...
-
11
ItsMyCode | If you are accessing the list elements in Python, you need to access it using its index position. If you specify a tuple or a list as an index, Python will throw typeerror: list indices must be integers or slices,...
-
5
VS Code Gold (14 Part Series) When you are building websites, sometimes you need to experiment with different values to get things just right. You are playi...
-
5
BusinessSolana-Based DeFi Protocol Synchrony Raises $4.2M for Composable IndicesThe funding, led by by Sanctor Capital, Wintermute Trading and...
-
8
Elasticsearch.Nest 教程系列 9-7 转换:Indices Paths | 索引路径 create: 2020-01-23 11:01:01 | update: 2020-01-23 12:15:44 本文总阅读量: 198 次...
-
5
<?xml encoding="utf-8" ??>Introduction In MySQL, a primary key is a field that uniquely identifies each record in a table. For instance, student_id, employee_id, ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK