From 629a6b3f574b1dcba123bf596448ad322952f6ee Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 15:54:37 -0400 Subject: [PATCH 1/7] javascript interview problems --- javascript.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 javascript.md diff --git a/javascript.md b/javascript.md new file mode 100644 index 0000000..370f0bd --- /dev/null +++ b/javascript.md @@ -0,0 +1,33 @@ + +# Javascript Developer + +## Language Problems + +### Context Binding + +Make the following code work (ie. should output only "Hello world" to the +console) without writing any **new** functions or changing any code outside of the +`bind` function. Explain what you did and why/when this would be useful. + + +```javascript + +function bind(func, context) { + // TODO implement this function +} + +function sayHello() { + console.log(this.bar); +} + +var Foo = function() { + this.bar = 'Hello World'; +}; + +var foo = new Foo(); +bind(sayHello, foo)(); +``` + +## jQuery / DOM Problems +## Framework / Design Problems + From d600a81f811c640900ad1254b1a95a77d533afaf Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 16:09:32 -0400 Subject: [PATCH 2/7] implementing an extend function --- README.md | 1 + javascript.md | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dfa4c73..bf66bf3 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,4 @@ Join-Us If you're checking out our code, why not let us check out yours? We're always looking for talented developers! * [Front End Development](front-end.md) +* [Javascript Development](javascript.md) diff --git a/javascript.md b/javascript.md index 370f0bd..78dc49a 100644 --- a/javascript.md +++ b/javascript.md @@ -11,7 +11,6 @@ console) without writing any **new** functions or changing any code outside of t ```javascript - function bind(func, context) { // TODO implement this function } @@ -28,6 +27,27 @@ var foo = new Foo(); bind(sayHello, foo)(); ``` +## Instantiation Techniques + +Make the following code work by implementing only the first method. Explain why +this method would be useful. + +```javascript +function extend(obj) { + // implement this function +} + +var Foo = function(args) { + extend(this, args); +} + +var foo = new Foo({firstName: 'Hello', lastName: 'World'}); + +// should print Hello World +console.log(foo.firstName + ' ' + foo.lastName); +``` + + ## jQuery / DOM Problems ## Framework / Design Problems From acb574d806f1a2e12fb68857f993983b2fd8fe7d Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 16:15:42 -0400 Subject: [PATCH 3/7] fix indent --- javascript.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/javascript.md b/javascript.md index 78dc49a..cb15033 100644 --- a/javascript.md +++ b/javascript.md @@ -27,7 +27,7 @@ var foo = new Foo(); bind(sayHello, foo)(); ``` -## Instantiation Techniques +### Instantiation Techniques Make the following code work by implementing only the first method. Explain why this method would be useful. @@ -49,5 +49,10 @@ console.log(foo.firstName + ' ' + foo.lastName); ## jQuery / DOM Problems + +### Selectors + +### Events + ## Framework / Design Problems From 502245fa8dc64e3df4edebdab8aa4dcaa4f185da Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 16:46:02 -0400 Subject: [PATCH 4/7] recursion --- javascript.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/javascript.md b/javascript.md index cb15033..1a2898b 100644 --- a/javascript.md +++ b/javascript.md @@ -3,6 +3,31 @@ ## Language Problems +### Recursion + +Count the number of strings in the `data` array and all nested arrays in +a recursive fashion. + + +```javascript + var data = [ + "test", + ["a", "b", "c"], + [["x", "y"], "z"], + "hello", + "world", + "something", + ["a", ["b", "c"], "d"] + ]; + + function countStrings(arr) { + // implement only this function body + } + + console.log("Strings: ", countStrings(data)); +``` + + ### Context Binding Make the following code work (ie. should output only "Hello world" to the From 4e94eedd6c1de0604354e2a38c53f6012fa77d2e Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 23:26:30 -0400 Subject: [PATCH 5/7] javascript questions --- javascript.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 5 deletions(-) diff --git a/javascript.md b/javascript.md index 1a2898b..bc42837 100644 --- a/javascript.md +++ b/javascript.md @@ -1,6 +1,10 @@ # Javascript Developer +Extra points for creative solutions. Even if a "correct" solution cannot be +found an incorrect one can let us see what skills you have and start a +discussion. + ## Language Problems ### Recursion @@ -17,7 +21,7 @@ a recursive fashion. "hello", "world", "something", - ["a", ["b", "c"], "d"] + ["a", ["b", "c"], "d", "b"] ]; function countStrings(arr) { @@ -36,9 +40,7 @@ console) without writing any **new** functions or changing any code outside of t ```javascript -function bind(func, context) { - // TODO implement this function -} +// implement `bind` here function sayHello() { console.log(this.bar); @@ -72,12 +74,125 @@ var foo = new Foo({firstName: 'Hello', lastName: 'World'}); console.log(foo.firstName + ' ' + foo.lastName); ``` +### Sorting + +Sort the `data` array using the `position` property of each object from lowest +to highest. Assume each element of the array is an object with a position +property and it is a Number. Use Javascripts built-in `Array.sort` + +```javascript +var data = [ + {id:1, position: 10, name: 'foo'}, + {id:2, position: 12, name: 'bar'}, + {id:3, position: 1, name: 'foo'}, + {id:5, position: 20, name: 'foo'}, + {id:4, position: 4.5, name: 'bar'} +] + +// sort here +``` ## jQuery / DOM Problems + +### Event Delegation + +Log the HTML tag name of the element being clicked on. Explain + + +```html +

+Hello World from javascript. +

+```` + +```javascript +jQuery('body').click(function(ev) { + // print the tag name here +}); +``` + ### Selectors -### Events +Toggle the display of the semantic children of header HTML tags (ie. make them +hidden/shown) whenever a parent *header* tag (h1, h2, h3, etc) is clicked. High +priority header tags should collapse all lower priority tags they contain (ie. +clicking `h1` collapses all `h2` tags in it's 'section'). Do not modify the +HTML. + +Extra credit for brevity and/or creative solutions. + +```html +

Foo

+

This is a test of the emergency broadcast system.

+ +

Bar

+

This is a test of the emergency broadcast system.

+

This is a test of the emergency broadcast system.

+ +

Foo

+

This is a test of the emergency broadcast system.

+ +

Foo 2

+ +

Foo Bar

+ +

Bar Foo

+

This is a test of the emergency broadcast system.

+ +

Bar Bar

+

This is a test of the emergency broadcast system.

+ +

Foo Foo

+

This is a test of the emergency broadcast system.

+ +

Bar bar bar

+

This is a test of the emergency broadcast system.

+

This is a test of the emergency broadcast system.

+``` + +```javascript +// implement the 'click' handler(s) +``` ## Framework / Design Problems +### Dependency Injection + +Write two functions: `register` and `using`. `register` takes a string and a +javascript object (function, object, string, ...). `using` takes an array of +strings and a function as it's arguments. + +Your goal is for your `using` function to provide it's function argument with +all the items give in it's array argument previously registered via the +`register` function by that name. `using` should provide it's function argument +with these *dependencies* in the order specified as arguments. + +The `using` function should fail if an string is provided that was not +previously registered. + +Discuss why a system like this might be useful. Discuss current javascript +implementations of this pattern. + +```javascript +// implement your register/using functions here +// you can have support variables/structures + +register('Foo', "Hello World"); +register('bar', function() { console.log("Hello World"); }); +register('bam', { a: 'Hello', b: 'World'}); + +// the following should log "Hello World" to the console 3 times +using(['bam', 'bar', 'Foo'], function(a, b, c) { + b(); + console.log(c); + console.log(a.a, a.b); +}); + +// this should print "Invalid Service" +try { + using(['box'], function() { console.log("Hello world"); }); +} catch(e) { + console.log(e); +} +``` From 04d5845a1476a7e881a880b5d59a6f36e8c37508 Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 23:43:00 -0400 Subject: [PATCH 6/7] Update javascript.md --- javascript.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript.md b/javascript.md index bc42837..c22a105 100644 --- a/javascript.md +++ b/javascript.md @@ -35,7 +35,7 @@ a recursive fashion. ### Context Binding Make the following code work (ie. should output only "Hello world" to the -console) without writing any **new** functions or changing any code outside of the +console) by implementing the `bind` function or changing any code outside of the `bind` function. Explain what you did and why/when this would be useful. From 3625a849fd6126eda3d3987147d934cdb9152220 Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Tue, 7 Oct 2014 23:45:57 -0400 Subject: [PATCH 7/7] Update javascript.md --- javascript.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/javascript.md b/javascript.md index c22a105..9987812 100644 --- a/javascript.md +++ b/javascript.md @@ -164,9 +164,10 @@ javascript object (function, object, string, ...). `using` takes an array of strings and a function as it's arguments. Your goal is for your `using` function to provide it's function argument with -all the items give in it's array argument previously registered via the -`register` function by that name. `using` should provide it's function argument -with these *dependencies* in the order specified as arguments. +all the items given in it's array argument previously registered via the +`register` function by that name. `using` should pass it's function arguments +containing these *dependencies* in the order specified in the array. See the +test code below for the intended usage. The `using` function should fail if an string is provided that was not previously registered.