Last active
December 20, 2015 05:58
-
-
Save SLaks/6081972 to your computer and use it in GitHub Desktop.
Interview Questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ajaxFindIndex(userIds, callback) { | |
for (var i = 0; i < userIds.length; i++) { | |
$.getJSON("http://some-api.com/get-user", { id: userIds[i] }, function (user) { | |
if (callback(user)) | |
return i; | |
}); | |
} | |
return -1; | |
} | |
var userManager = { | |
userIds: [1, 2, 3], | |
highlightUser: function (index) { }, | |
searchField: 'name', | |
search: function (searchText) { | |
var index = ajaxFindIndex(this.userIds, function (u) { | |
var corpus = u[this.searchField]; | |
return new RegExp(searchText, 'i').test(corpus)); | |
}); | |
this.highlightUser(index); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
escape("SELECT user_id FROM user WHERE email = " + email); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var userInput = prompt(...); | |
var htmlSource = "<h1>Contents...</h1>" | |
+ "<script>$('h1').click(function() { $(this).html(" + userInput + "); });</script>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/jquery/jquery/blob/master/src/core.js#L265-L327