Guest User

Untitled

a guest
May 26th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /**
  2. * Question 1
  3. *
  4. * a) What will be logged to the console?
  5. * b) How could the params in the call to getData be changed in order to log something else?
  6. */
  7. var getData = function(params) {
  8. if (typeof params.accountNumber !== 'number') {
  9. return Promise.reject({message: 'accountNumber must be of type: number'});
  10. } else {
  11. return Promise.resolve({foo: 'foo'});
  12. }
  13. };
  14.  
  15. getData({accountNumber: '1234'})
  16. .then(function(response) {
  17. console.log(response.foo);
  18. })
  19. .catch(function(error) {
  20. console.log(error.message);
  21. });
  22.  
  23.  
  24.  
  25. /**
  26. * Question 2
  27. *
  28. * Create a function that receives an array of credit card data and then:
  29. * a) filters out cards that end in 9
  30. * b) sorts the cards first by roleTypeCode, then by cardNumber
  31. */
  32. var cardsList = [
  33. {fullName: 'Star, Patrick', roleTypeCode: '03', cardNumber: '223456'},
  34. {fullName: 'Squarepants, Spongebob', roleTypeCode: '01', cardNumber: '987654'},
  35. {fullName: 'Tentacles, Squidward', roleTypeCode: '02', cardNumber: '765432'},
  36. {fullName: 'Tentacles, Squidward', roleTypeCode: '02', cardNumber: '465439'},
  37. {fullName: 'Star, Patrick', roleTypeCode: '03', cardNumber: '123456'}
  38. ];
  39.  
  40.  
  41.  
  42. /**
  43. * Question 3
  44. *
  45. * Create a function that receives a list of field configurations and a map of field id's and their values that
  46. * iterates through the list of fields and:
  47. * 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
  48. * b) removes the message property from a field if its value in the map of field values is truthy
  49. */
  50. var fieldConfigs = [
  51. {
  52. id: 'date',
  53. label: 'Date',
  54. inputType: 'date',
  55. options: {
  56. minDaysFromToday: 0
  57. },
  58. message: 'Field successfully updated'
  59. },
  60. {
  61. id: 'lastName',
  62. label: 'First Name',
  63. inputType: 'text',
  64. maxLength: 40,
  65. required: true
  66. },
  67. {
  68. id: 'firstName',
  69. label: 'First Name',
  70. inputType: 'text',
  71. maxLength: 40,
  72. required: true
  73. }
  74. ];
  75. var data = {
  76. date: '2020-01-01',
  77. lastName: 'Squarepants',
  78. firstName: ''
  79. };
Add Comment
Please, Sign In to add comment