Skip to content

Instantly share code, notes, and snippets.

@tomfuertes
Forked from rmurphey/screening.js
Last active August 29, 2015 14:14
Show Gist options
  • Save tomfuertes/9ddb1b7b7ef66bb17a80 to your computer and use it in GitHub Desktop.
Save tomfuertes/9ddb1b7b7ef66bb17a80 to your computer and use it in GitHub Desktop.
// Instructions: Take 3x passes w/ notes each time
// #.1: no console / no stackoverflow
// #.2: use console / no stackoverflow
// #.3: use console / use stackoverflow
// end result should look like:
// 1) How could you rewrite \n`{abc(xyz)}`?
// 1.1) I'd remove xyz like \n`abc()`
// 1.2) Confirmed works in console but needed to run it \n`abc()`
// 1.3) Googled and found this different approach I'd like more \n`if (!xyz) abc()}` (link to article / answer)
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// 2: a) what does the following code log?
// 2: b) how could you log the other variable and still maintain the optional fallback logic?
var foo = 'logme';
(function() {
var foo = foo || 'fallback';
console.log(foo);
})();
// 3: given the following code, how would you override the value of the bar
// property for the variable foo without affecting the value of the bar
// property for the variable bim? how would you affect the value of the bar
// property for both foo and bim? how would you add a method to foo and bim to
// console.log the value of each object's bar property? how would you tell if
// the object's bar property had been overridden for the particular object?
var Thinger = function() {
return this;
};
Thinger.prototype = {
bar : 'baz'
};
var foo = new Thinger(),
bim = new Thinger();
// 4: given the following code, and assuming that each defined object has a
// 'destroy' method, how would you destroy all of the objects contained in the
// myObjects object?
var myObjects = {
thinger : new myApp.Thinger(),
gizmo : new myApp.Gizmo(),
widget : new myApp.Widget()
};
// 5: given the following array, create an array that contains the contents of
// each array item repeated three times, with a space between each item. so,
// for example, if an array item is 'foo' then the new array should contain an
// array item 'foo foo foo'. (you can assume the library of your choice is
// available)
var myArray = [ 'foo', 'bar', 'baz' ];
// 6: a) How could you improve the following code?
// 6: b) What assuptions did you make in your improvement?
// 6: c) What would you ask around requirements / comments to help clarify those assumptions?
$(document).ready(function() {
$('.foo #bar').css('color', 'red');
$('.foo #bar').css('border', '1px solid blue');
$('.foo #bar').text('new text!');
$('.foo #bar').click(function() {
$(this).attr('title', 'new title');
$(this).width('100px');
});
$('.foo #bar').click();
});
// 7: what issues do you see with the following code? how would you fix it?
(function() {
var foo;
$.get({
url : 'foo.php',
success : function(resp) {
foo = resp.foo;
}
});
if (foo) {
// run this important code
}
})();
// 8: how could you rewrite the following code to make it shorter?
(function($){
$('li.foo a').attr('title', 'i am foo');
$('li.bar a').attr('title', 'i am bar');
$('li.baz a').attr('title', 'i am baz');
$('li.bop a').attr('title', 'i am bop');
})(window.jQuery);
// 9: b) what's non-performant about the following code?
// 9: c) how would you DRY up the code below?
for (i = 0; i <= 100; i++) {
$('#thinger').append('<p><span class="thinger">i am thinger ' + i + '</span></p>');
$('#gizmo').append('<p><span class="gizmo">i am gizmo ' + i + '</span></p>');
}
// 10: given the following data structure, write code that returns an array
// containing the name of each item, followed by a comma-separated list of
// the item's extras, if it has any. e.g.
//
// [ "Salad (Chicken, Steak, Shrimp)", ... ]
//
// (you can assume the library of your choice is available)
var menuItems = [
{ id : 1, name : 'Salad', extras : [ 'Chicken', 'Steak', 'Shrimp' ] },
{ id : 2, name : 'Potato', extras : [ 'Bacon', 'Sour Cream', 'Shrimp' ] },
{ id : 3, name : 'Sandwich', extras : [ 'Turkey', 'Bacon' ] },
{ id : 4, name : 'Bread' }
];
// BONUS: write code such that the following alerts "Hello World"
say('Hello')('World');
/*
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <[email protected]>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment