Skip to content

Instantly share code, notes, and snippets.

@SLaks
Last active December 20, 2015 05:58
Show Gist options
  • Save SLaks/6081972 to your computer and use it in GitHub Desktop.
Save SLaks/6081972 to your computer and use it in GitHub Desktop.
Interview Questions
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);
}
};
escape("SELECT user_id FROM user WHERE email = " + email);
var userInput = prompt(...);
var htmlSource = "<h1>Contents...</h1>"
+ "<script>$('h1').click(function() { $(this).html(" + userInput + "); });</script>";
@SLaks
Copy link
Author

SLaks commented Jul 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment