Secret Santa Application : Practical Interview Test
$begingroup$
I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare.
The guidelines were:
- Should work on IE8
- Use CDN's for external libraries
- Use whichever library(ies) you prefer
- Should take 2 hours
The code below is condensed into one file for convenience. There is a working version at http://54.201.30.172/frontend-challenge/
<div id="app">
<!-- Generated Secret Santa assignments should go here -->
<div id='participant-list'>
</div>
</div>
<script type="text/template" id="rootTemplate">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td>
<input type="checkbox" class="preventDups" name="preventDups" <% if(preventDuplicates){ %> checked <% } %> />No Buy Backs
</td>
<td></td>
<td></td>
<td></td>
<td>
<button class="shuffleButton">Reshuffle</button>
</td>
</tr>
</tfoot>
</script>
<script type="text/template" id="oneParticipantTpl">
<td> <%= name.first %> <%= name.last %> </td>
<td> </td>
<td> buys for </td>
<td> </td>
<% if(buysFor){ %>
<td id="<%= buysFor.guid %>"> <%= buysFor.name.first %> <%= buysFor.name.last %> </td>
<% } %>
</script>
<script type="text/javascript">
(function(){
var UserModel = Backbone.Model.extend({
idAttribute : 'guid',
defaults:{
"name": {
"first": "",
"last": ""
},
"email": "",
"phone": "",
"buysFor": null
},
initialize: function(){
// The user cannot buy for themselves
// Store their own id in an array of ids they can't buy for
// Any additional users that they can't buy for will be added here too
this.set('cantBuyFor', [this.get('guid')]);
// Set the display name for convenience
this.set('displayName', this.get('name').first + ' ' + this.get('name').last)
}
});
var UsersCollection = Backbone.Collection.extend({
model : UserModel,
url : 'users.json',
// Parse the users property from the ajax request
parse: function(resp){
return resp.users;
}
});
var OneParticipantView = Mn.ItemView.extend({
// Childview of All particiapnts view
// Renders each row in the table
template: '#oneParticipantTpl',
tagName: 'tr'
});
var AllParticipantsViewModel = Backbone.Model.extend({
// model to render and control whether recipients can buy for their buyers (buy backs)
defaults : {
preventDuplicates: true
}
});
var AllParticipantsView = Mn.CompositeView.extend({
template : '#rootTemplate',
childView : OneParticipantView,
childViewContainer: 'tbody',
tagName: 'table',
model : new AllParticipantsViewModel(),
// Make sure that we render the table when the collection is updated from the server
collectionEvents: {
'sync': 'reShuffle'
},
ui: {
shuffleButton: '.shuffleButton',
dupsCheckbox : '.preventDups'
},
events: {
'click @ui.shuffleButton': 'reShuffle',
'click @ui.dupsCheckbox' : 'changeDups'
},
changeDups: function(e){
// toggle whether buy backs are enabled
// Set the view-model property to whatever the user has selected and rerender the list
e.preventDefault();
var $checkbox = $(e.currentTarget);
if($checkbox.is(':checked')){
this.model.set('preventDuplicates', true);
}else{
this.model.set('preventDuplicates', false);
}
return this.render();
},
initialize : function(){
// This can be used if the models are bootstrapped into the page rather than loaded over ajax
//this.shuffle();
},
validRecipients: function(buyer, boughtFor){
// Returns the list of people the buyer can buy for
// This should be everyone less people who have already been bought for and anyone the buyer is forbidden to buy for (themselves)
var validRecipients = this.collection.clone();
validRecipients.remove(buyer.get('cantBuyFor'));
validRecipients.remove(boughtFor);
return validRecipients;
},
validSwaps: function(buyer){
// Returns a list of people the buyer can swap without breaking rules
var validSwaps = this.collection.clone();
validSwaps.filter(function(recipient){
return buyer.get('cantBuyFor').indexOf(recipient.get('guid')) === -1;
});
return validSwaps;
},
randomDraw: function(max){
// Random number generator
return Math.floor(Math.random() * max);
},
preventDuplicatesDraw: function(buyer, recipient){
// Prevent the recipient from buying back to the buyer if duplicates are disabled
if(this.model.get('preventDuplicates')){
recipient.get('cantBuyFor').splice(0,0, buyer.get('guid'));
}else{
return false;
}
},
shuffle: function(){
var boughtFor = ;
this.collection.each(function(buyer, idx){
// get all the valid recipients for this buyer as a backbone collection
// NB. Valid recipients is not this.collection, it is a clone
var validRecipients = this.validRecipients(buyer, boughtFor);
if(validRecipients.length){
// remove the recipient from the hat and match it to the actual human recipient
var recipientTicket = validRecipients.at(this.randomDraw(validRecipients.length));
var recipient = this.collection.get(recipientTicket.get('guid'));
// give the recipient to the buyer
buyer.set('buysFor', recipient.toJSON());
this.preventDuplicatesDraw(buyer, recipient);
// Set aside the recipients ticket
boughtFor.push(recipient.get('guid'));
}else{
this.makeSwap(buyer);
}
}, this);
return this.collection;
},
makeSwap : function(buyer){
// Pick out a person to swap with at random (not the last)
var validSwaps = this.validRecipients(buyer, );
var randomSwapper = this.collection.at(this.randomDraw(validSwaps.length));
// Temporarily leave one person to buy for themselves
buyer.set('buysFor', randomSwapper.get('buysFor'));
// Swap with someone
randomSwapper.set('buysFor', buyer.toJSON());
},
reShuffle: function(){
// Shuffle reassign the pairs and reset the collection
// Resetting the collection will rerender the list
var reShuffled = this.shuffle();
this.collection.reset(reShuffled.toJSON());
}
});
var RootView = Mn.LayoutView.extend({
el: '#app',
regions : {
"participantList": "#participant-list"
},
initialize: function() {
// pass the collection down to the composite view
this.getRegion('participantList').show(new AllParticipantsView({
collection : this.collection
}));
}
});
var usersColl = new UsersCollection();
var app = new Mn.Application({
container : 'body',
rootView : new RootView({collection:usersColl})
});
usersColl.fetch().then(function(){
app.start();
});
})();
</script>
javascript interview-questions promise backbone.js marionette.js
$endgroup$
add a comment |
$begingroup$
I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare.
The guidelines were:
- Should work on IE8
- Use CDN's for external libraries
- Use whichever library(ies) you prefer
- Should take 2 hours
The code below is condensed into one file for convenience. There is a working version at http://54.201.30.172/frontend-challenge/
<div id="app">
<!-- Generated Secret Santa assignments should go here -->
<div id='participant-list'>
</div>
</div>
<script type="text/template" id="rootTemplate">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td>
<input type="checkbox" class="preventDups" name="preventDups" <% if(preventDuplicates){ %> checked <% } %> />No Buy Backs
</td>
<td></td>
<td></td>
<td></td>
<td>
<button class="shuffleButton">Reshuffle</button>
</td>
</tr>
</tfoot>
</script>
<script type="text/template" id="oneParticipantTpl">
<td> <%= name.first %> <%= name.last %> </td>
<td> </td>
<td> buys for </td>
<td> </td>
<% if(buysFor){ %>
<td id="<%= buysFor.guid %>"> <%= buysFor.name.first %> <%= buysFor.name.last %> </td>
<% } %>
</script>
<script type="text/javascript">
(function(){
var UserModel = Backbone.Model.extend({
idAttribute : 'guid',
defaults:{
"name": {
"first": "",
"last": ""
},
"email": "",
"phone": "",
"buysFor": null
},
initialize: function(){
// The user cannot buy for themselves
// Store their own id in an array of ids they can't buy for
// Any additional users that they can't buy for will be added here too
this.set('cantBuyFor', [this.get('guid')]);
// Set the display name for convenience
this.set('displayName', this.get('name').first + ' ' + this.get('name').last)
}
});
var UsersCollection = Backbone.Collection.extend({
model : UserModel,
url : 'users.json',
// Parse the users property from the ajax request
parse: function(resp){
return resp.users;
}
});
var OneParticipantView = Mn.ItemView.extend({
// Childview of All particiapnts view
// Renders each row in the table
template: '#oneParticipantTpl',
tagName: 'tr'
});
var AllParticipantsViewModel = Backbone.Model.extend({
// model to render and control whether recipients can buy for their buyers (buy backs)
defaults : {
preventDuplicates: true
}
});
var AllParticipantsView = Mn.CompositeView.extend({
template : '#rootTemplate',
childView : OneParticipantView,
childViewContainer: 'tbody',
tagName: 'table',
model : new AllParticipantsViewModel(),
// Make sure that we render the table when the collection is updated from the server
collectionEvents: {
'sync': 'reShuffle'
},
ui: {
shuffleButton: '.shuffleButton',
dupsCheckbox : '.preventDups'
},
events: {
'click @ui.shuffleButton': 'reShuffle',
'click @ui.dupsCheckbox' : 'changeDups'
},
changeDups: function(e){
// toggle whether buy backs are enabled
// Set the view-model property to whatever the user has selected and rerender the list
e.preventDefault();
var $checkbox = $(e.currentTarget);
if($checkbox.is(':checked')){
this.model.set('preventDuplicates', true);
}else{
this.model.set('preventDuplicates', false);
}
return this.render();
},
initialize : function(){
// This can be used if the models are bootstrapped into the page rather than loaded over ajax
//this.shuffle();
},
validRecipients: function(buyer, boughtFor){
// Returns the list of people the buyer can buy for
// This should be everyone less people who have already been bought for and anyone the buyer is forbidden to buy for (themselves)
var validRecipients = this.collection.clone();
validRecipients.remove(buyer.get('cantBuyFor'));
validRecipients.remove(boughtFor);
return validRecipients;
},
validSwaps: function(buyer){
// Returns a list of people the buyer can swap without breaking rules
var validSwaps = this.collection.clone();
validSwaps.filter(function(recipient){
return buyer.get('cantBuyFor').indexOf(recipient.get('guid')) === -1;
});
return validSwaps;
},
randomDraw: function(max){
// Random number generator
return Math.floor(Math.random() * max);
},
preventDuplicatesDraw: function(buyer, recipient){
// Prevent the recipient from buying back to the buyer if duplicates are disabled
if(this.model.get('preventDuplicates')){
recipient.get('cantBuyFor').splice(0,0, buyer.get('guid'));
}else{
return false;
}
},
shuffle: function(){
var boughtFor = ;
this.collection.each(function(buyer, idx){
// get all the valid recipients for this buyer as a backbone collection
// NB. Valid recipients is not this.collection, it is a clone
var validRecipients = this.validRecipients(buyer, boughtFor);
if(validRecipients.length){
// remove the recipient from the hat and match it to the actual human recipient
var recipientTicket = validRecipients.at(this.randomDraw(validRecipients.length));
var recipient = this.collection.get(recipientTicket.get('guid'));
// give the recipient to the buyer
buyer.set('buysFor', recipient.toJSON());
this.preventDuplicatesDraw(buyer, recipient);
// Set aside the recipients ticket
boughtFor.push(recipient.get('guid'));
}else{
this.makeSwap(buyer);
}
}, this);
return this.collection;
},
makeSwap : function(buyer){
// Pick out a person to swap with at random (not the last)
var validSwaps = this.validRecipients(buyer, );
var randomSwapper = this.collection.at(this.randomDraw(validSwaps.length));
// Temporarily leave one person to buy for themselves
buyer.set('buysFor', randomSwapper.get('buysFor'));
// Swap with someone
randomSwapper.set('buysFor', buyer.toJSON());
},
reShuffle: function(){
// Shuffle reassign the pairs and reset the collection
// Resetting the collection will rerender the list
var reShuffled = this.shuffle();
this.collection.reset(reShuffled.toJSON());
}
});
var RootView = Mn.LayoutView.extend({
el: '#app',
regions : {
"participantList": "#participant-list"
},
initialize: function() {
// pass the collection down to the composite view
this.getRegion('participantList').show(new AllParticipantsView({
collection : this.collection
}));
}
});
var usersColl = new UsersCollection();
var app = new Mn.Application({
container : 'body',
rootView : new RootView({collection:usersColl})
});
usersColl.fetch().then(function(){
app.start();
});
})();
</script>
javascript interview-questions promise backbone.js marionette.js
$endgroup$
$begingroup$
At this moment I personally do not consider this a good question. Please see this checklist for how to write a good Code Review question for how you can improve it.
$endgroup$
– Simon Forsberg♦
Jan 19 '16 at 14:04
add a comment |
$begingroup$
I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare.
The guidelines were:
- Should work on IE8
- Use CDN's for external libraries
- Use whichever library(ies) you prefer
- Should take 2 hours
The code below is condensed into one file for convenience. There is a working version at http://54.201.30.172/frontend-challenge/
<div id="app">
<!-- Generated Secret Santa assignments should go here -->
<div id='participant-list'>
</div>
</div>
<script type="text/template" id="rootTemplate">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td>
<input type="checkbox" class="preventDups" name="preventDups" <% if(preventDuplicates){ %> checked <% } %> />No Buy Backs
</td>
<td></td>
<td></td>
<td></td>
<td>
<button class="shuffleButton">Reshuffle</button>
</td>
</tr>
</tfoot>
</script>
<script type="text/template" id="oneParticipantTpl">
<td> <%= name.first %> <%= name.last %> </td>
<td> </td>
<td> buys for </td>
<td> </td>
<% if(buysFor){ %>
<td id="<%= buysFor.guid %>"> <%= buysFor.name.first %> <%= buysFor.name.last %> </td>
<% } %>
</script>
<script type="text/javascript">
(function(){
var UserModel = Backbone.Model.extend({
idAttribute : 'guid',
defaults:{
"name": {
"first": "",
"last": ""
},
"email": "",
"phone": "",
"buysFor": null
},
initialize: function(){
// The user cannot buy for themselves
// Store their own id in an array of ids they can't buy for
// Any additional users that they can't buy for will be added here too
this.set('cantBuyFor', [this.get('guid')]);
// Set the display name for convenience
this.set('displayName', this.get('name').first + ' ' + this.get('name').last)
}
});
var UsersCollection = Backbone.Collection.extend({
model : UserModel,
url : 'users.json',
// Parse the users property from the ajax request
parse: function(resp){
return resp.users;
}
});
var OneParticipantView = Mn.ItemView.extend({
// Childview of All particiapnts view
// Renders each row in the table
template: '#oneParticipantTpl',
tagName: 'tr'
});
var AllParticipantsViewModel = Backbone.Model.extend({
// model to render and control whether recipients can buy for their buyers (buy backs)
defaults : {
preventDuplicates: true
}
});
var AllParticipantsView = Mn.CompositeView.extend({
template : '#rootTemplate',
childView : OneParticipantView,
childViewContainer: 'tbody',
tagName: 'table',
model : new AllParticipantsViewModel(),
// Make sure that we render the table when the collection is updated from the server
collectionEvents: {
'sync': 'reShuffle'
},
ui: {
shuffleButton: '.shuffleButton',
dupsCheckbox : '.preventDups'
},
events: {
'click @ui.shuffleButton': 'reShuffle',
'click @ui.dupsCheckbox' : 'changeDups'
},
changeDups: function(e){
// toggle whether buy backs are enabled
// Set the view-model property to whatever the user has selected and rerender the list
e.preventDefault();
var $checkbox = $(e.currentTarget);
if($checkbox.is(':checked')){
this.model.set('preventDuplicates', true);
}else{
this.model.set('preventDuplicates', false);
}
return this.render();
},
initialize : function(){
// This can be used if the models are bootstrapped into the page rather than loaded over ajax
//this.shuffle();
},
validRecipients: function(buyer, boughtFor){
// Returns the list of people the buyer can buy for
// This should be everyone less people who have already been bought for and anyone the buyer is forbidden to buy for (themselves)
var validRecipients = this.collection.clone();
validRecipients.remove(buyer.get('cantBuyFor'));
validRecipients.remove(boughtFor);
return validRecipients;
},
validSwaps: function(buyer){
// Returns a list of people the buyer can swap without breaking rules
var validSwaps = this.collection.clone();
validSwaps.filter(function(recipient){
return buyer.get('cantBuyFor').indexOf(recipient.get('guid')) === -1;
});
return validSwaps;
},
randomDraw: function(max){
// Random number generator
return Math.floor(Math.random() * max);
},
preventDuplicatesDraw: function(buyer, recipient){
// Prevent the recipient from buying back to the buyer if duplicates are disabled
if(this.model.get('preventDuplicates')){
recipient.get('cantBuyFor').splice(0,0, buyer.get('guid'));
}else{
return false;
}
},
shuffle: function(){
var boughtFor = ;
this.collection.each(function(buyer, idx){
// get all the valid recipients for this buyer as a backbone collection
// NB. Valid recipients is not this.collection, it is a clone
var validRecipients = this.validRecipients(buyer, boughtFor);
if(validRecipients.length){
// remove the recipient from the hat and match it to the actual human recipient
var recipientTicket = validRecipients.at(this.randomDraw(validRecipients.length));
var recipient = this.collection.get(recipientTicket.get('guid'));
// give the recipient to the buyer
buyer.set('buysFor', recipient.toJSON());
this.preventDuplicatesDraw(buyer, recipient);
// Set aside the recipients ticket
boughtFor.push(recipient.get('guid'));
}else{
this.makeSwap(buyer);
}
}, this);
return this.collection;
},
makeSwap : function(buyer){
// Pick out a person to swap with at random (not the last)
var validSwaps = this.validRecipients(buyer, );
var randomSwapper = this.collection.at(this.randomDraw(validSwaps.length));
// Temporarily leave one person to buy for themselves
buyer.set('buysFor', randomSwapper.get('buysFor'));
// Swap with someone
randomSwapper.set('buysFor', buyer.toJSON());
},
reShuffle: function(){
// Shuffle reassign the pairs and reset the collection
// Resetting the collection will rerender the list
var reShuffled = this.shuffle();
this.collection.reset(reShuffled.toJSON());
}
});
var RootView = Mn.LayoutView.extend({
el: '#app',
regions : {
"participantList": "#participant-list"
},
initialize: function() {
// pass the collection down to the composite view
this.getRegion('participantList').show(new AllParticipantsView({
collection : this.collection
}));
}
});
var usersColl = new UsersCollection();
var app = new Mn.Application({
container : 'body',
rootView : new RootView({collection:usersColl})
});
usersColl.fetch().then(function(){
app.start();
});
})();
</script>
javascript interview-questions promise backbone.js marionette.js
$endgroup$
I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare.
The guidelines were:
- Should work on IE8
- Use CDN's for external libraries
- Use whichever library(ies) you prefer
- Should take 2 hours
The code below is condensed into one file for convenience. There is a working version at http://54.201.30.172/frontend-challenge/
<div id="app">
<!-- Generated Secret Santa assignments should go here -->
<div id='participant-list'>
</div>
</div>
<script type="text/template" id="rootTemplate">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td>
<input type="checkbox" class="preventDups" name="preventDups" <% if(preventDuplicates){ %> checked <% } %> />No Buy Backs
</td>
<td></td>
<td></td>
<td></td>
<td>
<button class="shuffleButton">Reshuffle</button>
</td>
</tr>
</tfoot>
</script>
<script type="text/template" id="oneParticipantTpl">
<td> <%= name.first %> <%= name.last %> </td>
<td> </td>
<td> buys for </td>
<td> </td>
<% if(buysFor){ %>
<td id="<%= buysFor.guid %>"> <%= buysFor.name.first %> <%= buysFor.name.last %> </td>
<% } %>
</script>
<script type="text/javascript">
(function(){
var UserModel = Backbone.Model.extend({
idAttribute : 'guid',
defaults:{
"name": {
"first": "",
"last": ""
},
"email": "",
"phone": "",
"buysFor": null
},
initialize: function(){
// The user cannot buy for themselves
// Store their own id in an array of ids they can't buy for
// Any additional users that they can't buy for will be added here too
this.set('cantBuyFor', [this.get('guid')]);
// Set the display name for convenience
this.set('displayName', this.get('name').first + ' ' + this.get('name').last)
}
});
var UsersCollection = Backbone.Collection.extend({
model : UserModel,
url : 'users.json',
// Parse the users property from the ajax request
parse: function(resp){
return resp.users;
}
});
var OneParticipantView = Mn.ItemView.extend({
// Childview of All particiapnts view
// Renders each row in the table
template: '#oneParticipantTpl',
tagName: 'tr'
});
var AllParticipantsViewModel = Backbone.Model.extend({
// model to render and control whether recipients can buy for their buyers (buy backs)
defaults : {
preventDuplicates: true
}
});
var AllParticipantsView = Mn.CompositeView.extend({
template : '#rootTemplate',
childView : OneParticipantView,
childViewContainer: 'tbody',
tagName: 'table',
model : new AllParticipantsViewModel(),
// Make sure that we render the table when the collection is updated from the server
collectionEvents: {
'sync': 'reShuffle'
},
ui: {
shuffleButton: '.shuffleButton',
dupsCheckbox : '.preventDups'
},
events: {
'click @ui.shuffleButton': 'reShuffle',
'click @ui.dupsCheckbox' : 'changeDups'
},
changeDups: function(e){
// toggle whether buy backs are enabled
// Set the view-model property to whatever the user has selected and rerender the list
e.preventDefault();
var $checkbox = $(e.currentTarget);
if($checkbox.is(':checked')){
this.model.set('preventDuplicates', true);
}else{
this.model.set('preventDuplicates', false);
}
return this.render();
},
initialize : function(){
// This can be used if the models are bootstrapped into the page rather than loaded over ajax
//this.shuffle();
},
validRecipients: function(buyer, boughtFor){
// Returns the list of people the buyer can buy for
// This should be everyone less people who have already been bought for and anyone the buyer is forbidden to buy for (themselves)
var validRecipients = this.collection.clone();
validRecipients.remove(buyer.get('cantBuyFor'));
validRecipients.remove(boughtFor);
return validRecipients;
},
validSwaps: function(buyer){
// Returns a list of people the buyer can swap without breaking rules
var validSwaps = this.collection.clone();
validSwaps.filter(function(recipient){
return buyer.get('cantBuyFor').indexOf(recipient.get('guid')) === -1;
});
return validSwaps;
},
randomDraw: function(max){
// Random number generator
return Math.floor(Math.random() * max);
},
preventDuplicatesDraw: function(buyer, recipient){
// Prevent the recipient from buying back to the buyer if duplicates are disabled
if(this.model.get('preventDuplicates')){
recipient.get('cantBuyFor').splice(0,0, buyer.get('guid'));
}else{
return false;
}
},
shuffle: function(){
var boughtFor = ;
this.collection.each(function(buyer, idx){
// get all the valid recipients for this buyer as a backbone collection
// NB. Valid recipients is not this.collection, it is a clone
var validRecipients = this.validRecipients(buyer, boughtFor);
if(validRecipients.length){
// remove the recipient from the hat and match it to the actual human recipient
var recipientTicket = validRecipients.at(this.randomDraw(validRecipients.length));
var recipient = this.collection.get(recipientTicket.get('guid'));
// give the recipient to the buyer
buyer.set('buysFor', recipient.toJSON());
this.preventDuplicatesDraw(buyer, recipient);
// Set aside the recipients ticket
boughtFor.push(recipient.get('guid'));
}else{
this.makeSwap(buyer);
}
}, this);
return this.collection;
},
makeSwap : function(buyer){
// Pick out a person to swap with at random (not the last)
var validSwaps = this.validRecipients(buyer, );
var randomSwapper = this.collection.at(this.randomDraw(validSwaps.length));
// Temporarily leave one person to buy for themselves
buyer.set('buysFor', randomSwapper.get('buysFor'));
// Swap with someone
randomSwapper.set('buysFor', buyer.toJSON());
},
reShuffle: function(){
// Shuffle reassign the pairs and reset the collection
// Resetting the collection will rerender the list
var reShuffled = this.shuffle();
this.collection.reset(reShuffled.toJSON());
}
});
var RootView = Mn.LayoutView.extend({
el: '#app',
regions : {
"participantList": "#participant-list"
},
initialize: function() {
// pass the collection down to the composite view
this.getRegion('participantList').show(new AllParticipantsView({
collection : this.collection
}));
}
});
var usersColl = new UsersCollection();
var app = new Mn.Application({
container : 'body',
rootView : new RootView({collection:usersColl})
});
usersColl.fetch().then(function(){
app.start();
});
})();
</script>
javascript interview-questions promise backbone.js marionette.js
javascript interview-questions promise backbone.js marionette.js
edited 1 hour ago
Sᴀᴍ Onᴇᴌᴀ
9,50062163
9,50062163
asked Jan 19 '16 at 10:23
brianfbrianf
1341
1341
$begingroup$
At this moment I personally do not consider this a good question. Please see this checklist for how to write a good Code Review question for how you can improve it.
$endgroup$
– Simon Forsberg♦
Jan 19 '16 at 14:04
add a comment |
$begingroup$
At this moment I personally do not consider this a good question. Please see this checklist for how to write a good Code Review question for how you can improve it.
$endgroup$
– Simon Forsberg♦
Jan 19 '16 at 14:04
$begingroup$
At this moment I personally do not consider this a good question. Please see this checklist for how to write a good Code Review question for how you can improve it.
$endgroup$
– Simon Forsberg♦
Jan 19 '16 at 14:04
$begingroup$
At this moment I personally do not consider this a good question. Please see this checklist for how to write a good Code Review question for how you can improve it.
$endgroup$
– Simon Forsberg♦
Jan 19 '16 at 14:04
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
If I was evaluating this code as a sample for an interview, I might be deterred by the inconsistent indentation - some blocks are indented with two spaces while others have four spaces. I do like the usage of templates and promises.
One suggestion I have would be to consider eliminating the extra lambda function when starting the application:
usersColl.fetch().then(function(){
app.start();
});
And use a reference to the start method as the promise callback:
usersColl.fetch().then(app.start);
This may complicate matters because the method would receive as arguments any parameters returned from the promise. If that becomes an issue, maybe a partially bound function would help.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f117241%2fsecret-santa-application-practical-interview-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
If I was evaluating this code as a sample for an interview, I might be deterred by the inconsistent indentation - some blocks are indented with two spaces while others have four spaces. I do like the usage of templates and promises.
One suggestion I have would be to consider eliminating the extra lambda function when starting the application:
usersColl.fetch().then(function(){
app.start();
});
And use a reference to the start method as the promise callback:
usersColl.fetch().then(app.start);
This may complicate matters because the method would receive as arguments any parameters returned from the promise. If that becomes an issue, maybe a partially bound function would help.
$endgroup$
add a comment |
$begingroup$
If I was evaluating this code as a sample for an interview, I might be deterred by the inconsistent indentation - some blocks are indented with two spaces while others have four spaces. I do like the usage of templates and promises.
One suggestion I have would be to consider eliminating the extra lambda function when starting the application:
usersColl.fetch().then(function(){
app.start();
});
And use a reference to the start method as the promise callback:
usersColl.fetch().then(app.start);
This may complicate matters because the method would receive as arguments any parameters returned from the promise. If that becomes an issue, maybe a partially bound function would help.
$endgroup$
add a comment |
$begingroup$
If I was evaluating this code as a sample for an interview, I might be deterred by the inconsistent indentation - some blocks are indented with two spaces while others have four spaces. I do like the usage of templates and promises.
One suggestion I have would be to consider eliminating the extra lambda function when starting the application:
usersColl.fetch().then(function(){
app.start();
});
And use a reference to the start method as the promise callback:
usersColl.fetch().then(app.start);
This may complicate matters because the method would receive as arguments any parameters returned from the promise. If that becomes an issue, maybe a partially bound function would help.
$endgroup$
If I was evaluating this code as a sample for an interview, I might be deterred by the inconsistent indentation - some blocks are indented with two spaces while others have four spaces. I do like the usage of templates and promises.
One suggestion I have would be to consider eliminating the extra lambda function when starting the application:
usersColl.fetch().then(function(){
app.start();
});
And use a reference to the start method as the promise callback:
usersColl.fetch().then(app.start);
This may complicate matters because the method would receive as arguments any parameters returned from the promise. If that becomes an issue, maybe a partially bound function would help.
answered 1 hour ago
Sᴀᴍ OnᴇᴌᴀSᴀᴍ Onᴇᴌᴀ
9,50062163
9,50062163
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f117241%2fsecret-santa-application-practical-interview-test%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
At this moment I personally do not consider this a good question. Please see this checklist for how to write a good Code Review question for how you can improve it.
$endgroup$
– Simon Forsberg♦
Jan 19 '16 at 14:04