Last active
May 22, 2018 01:11
-
-
Save BrentonCozby/f978fcabde77e1223b2d375c3dfc0e28 to your computer and use it in GitHub Desktop.
JavaScript problems for an interview at a financial services company
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
/** | |
* Question 1 | |
* | |
* a) What will be logged to the console? | |
* b) How could the params in the call to getData be changed in order to log something else? | |
*/ | |
var getData = function(params) { | |
if (typeof params.accountNumber !== 'number') { | |
return Promise.reject({message: 'accountNumber must be of type: number'}); | |
} else { | |
return Promise.resolve({foo: 'foo'}); | |
} | |
}; | |
getData({accountNumber: '1234'}) | |
.then(function(response) { | |
console.log(response.foo); | |
}) | |
.catch(function(error) { | |
console.log(error.message); | |
}); | |
/** | |
* Question 2 | |
* | |
* Create a function that receives an array of credit card data and then: | |
* a) filters out cards that end in 9 | |
* b) sorts the cards first by roleTypeCode, then by cardNumber | |
*/ | |
var cardsList = [ | |
{fullName: 'Star, Patrick', roleTypeCode: '03', cardNumber: '223456'}, | |
{fullName: 'Squarepants, Spongebob', roleTypeCode: '01', cardNumber: '987654'}, | |
{fullName: 'Tentacles, Squidward', roleTypeCode: '02', cardNumber: '765432'}, | |
{fullName: 'Tentacles, Squidward', roleTypeCode: '02', cardNumber: '465439'}, | |
{fullName: 'Star, Patrick', roleTypeCode: '03', cardNumber: '123456'} | |
]; | |
/** | |
* Question 3 | |
* | |
* Create a function that receives a list of field configurations and a map of field id's and their values that | |
* iterates through the list of fields and: | |
* a) sets a field's message property to 'Field is required' if the map of field values has a falsy value for the field's id | |
* b) removes the message property from a field if its value in the map of field values is truthy | |
*/ | |
var fieldConfigs = [ | |
{ | |
id: 'date', | |
label: 'Date', | |
inputType: 'date', | |
options: { | |
minDaysFromToday: 0 | |
}, | |
message: 'Field successfully updated' | |
}, | |
{ | |
id: 'lastName', | |
label: 'First Name', | |
inputType: 'text', | |
maxLength: 40, | |
required: true | |
}, | |
{ | |
id: 'firstName', | |
label: 'First Name', | |
inputType: 'text', | |
maxLength: 40, | |
required: true | |
} | |
]; | |
var data = { | |
date: '2020-01-01', | |
lastName: 'Squarepants', | |
firstName: '' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment