11

A quiz about RegExp.prototype.exec return values and numeric indexes (or indices...

 4 years ago
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.
neoserver,ios ssh client
A quiz about RegExp.prototype.exec return values and numeric indexes (or indices or however you people pluralize that word).

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.

© 3000. Mike Taylr Dot Com Web-Ring. File a bug on this blog.

<< Previous | Home | Next | Alva | Jenn | figital | Gianni | Ricky | Potch >>


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK