Advertisement
Guest User

Untitled

a guest
May 24th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. /**
  2. * @author Jason Seminara <js@ga.co>
  3. * @since 2017-07-12
  4. */
  5. const jsFunctionsLab = (() => {
  6. // Question 1
  7. /**
  8. * @func maxOfTwoNumbers
  9. * @desc Takes two numbers as arguments and returns the largest of them.
  10. * @hint Use the if-else construct available in Javascript.
  11. * Do some Googling to figure this out if you forget how conditionals work.
  12. * @param {Number} x - first number to evaulate
  13. * @param {Number} y - second number to evaulate
  14. * @returns {Number} - the smaller of x and y
  15. * @example
  16. > maxOfTwoNumbers(99, 5)
  17. => 99
  18. */
  19.  
  20. function maxOfTwoNumbers(x, y) {
  21. // CODE HERE
  22. return Math.max(x, y);
  23. }
  24. maxOfTwoNumbers(99, 5);
  25. // Question 2
  26. /**
  27. * @func maxOfThree
  28. * @desc Takes three numbers as arguments and returns the largest of them.
  29. * @param {Number} x - first number to evaulate
  30. * @param {Number} y - second number to evaulate
  31. * @param {Number} z - third number to evaulate
  32. * @returns {Number} - the larger of x, y, and z
  33. * @example
  34. > maxOfThree(4, 5, 9)
  35. => 9
  36. */
  37.  
  38. function maxOfThree(x, y, z) {
  39. // CODE HERE
  40.  
  41. return Math.max(x, y, z);
  42. }
  43. maxOfThree(4, 5, 9);
  44. // Question 3
  45. /**
  46. * @func isCharacterAVowel
  47. * @desc Takes a letter, determines if it's a vowel
  48. * @param {String} letter - string of length 1
  49. * @returns {Boolean} true if it is a vowel; false, otherwise
  50. * BONUS: this can be done on one line!
  51. * @example
  52. > isCharacterAVowel('a')
  53. => true
  54.  
  55. > isCharacterAVowel('n')
  56. => false
  57. */
  58.  
  59. function isCharacterAVowel(letter) {
  60. // CODE HERE
  61. }
  62.  
  63.  
  64. // BONUS 1
  65. /**
  66. * @func sumArray
  67. * @desc Takes an array; returns the sum of the items in the array
  68. * @param {Array} arr - string of length 1
  69. * @returns {Number} the sum of the items in the array
  70. * BONUS: this can be done on one line!
  71. * @example
  72. > sumArray(1, 2, 3, 4)
  73. => 10
  74. */
  75.  
  76. function sumArray(arr) {
  77. // CODE HERE
  78. }
  79.  
  80.  
  81. // BONUS 2
  82. /**
  83. * @func multiplyArray
  84. * @desc Takes an array; returns the product of the items in the array
  85. * @param {Array} arr - string of length 1
  86. * @returns {Number} the product of the items in the array
  87. * BONUS: this can be done on one line!
  88. * @example
  89. > multiplyArray(1, 2, 3, 4)
  90. => 24
  91. */
  92.  
  93. function multiplyArray(arr) {
  94. // CODE HERE
  95. }
  96.  
  97.  
  98. // BONUS 3
  99. /**
  100. * @func reverseString
  101. * @desc Takes a string, returns the reverse of it.
  102. * @param {String} stringToReverse - the string to reverse
  103. * @returns {String} the incoming string reversed
  104. * @example
  105. > reverseString('General Assembly')
  106. => "ylbmessA lareneG"
  107. */
  108.  
  109. function reverseString(stringToReverse) {
  110. // CODE HERE
  111. }
  112.  
  113. // BONUS 4
  114. /**
  115. * @func findLongestWord
  116. * @desc Takes an array of words, returns the length of the longest word.
  117. * @param {Array} arrayOfWords - an array of words
  118. * @returns {Number} the length of the longest word in the array
  119. * @example
  120. > findLongestWord(['short', 'longest', 'longer'])
  121. => 7
  122. */
  123.  
  124. function findLongestWord(arrayOfWords) {
  125. // CODE HERE
  126. }
  127.  
  128. // BONUS 5
  129. /**
  130. * @func filterLongWords
  131. * @desc Takes an array of words, returns only the words that are longer than 'i' chars.
  132. * @param {Array} arrayOfWords - an array of words
  133. * @param {Number} i
  134. * @returns {Array} a new array of words that are longer than `i` characters long.
  135. * @example
  136. > filterLongWords(['short', 'longest', 'longer'], 5)
  137. => ['longest', 'longer']
  138. */
  139.  
  140. function filterLongWords(arrayOfWords) {
  141. // CODE HERE
  142. }
  143.  
  144. // Bonus 6
  145. /**
  146. * @method characterCounts
  147. * @desc Takes a string; returns the character count for each letter in the string, regardless of case
  148. * @param {String} stringToCount - the string to enumerate
  149. * @returns {{char:occuranceCount}} an object where:
  150. - the keys are the characters that occur in the string
  151. - the values are the number of occurrences for each letter, regardless of the case
  152. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
  153. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
  154. * @example
  155. > characterCounts('General Assembly NYC');
  156. => {
  157. a: 2,
  158. b: 1,
  159. c: 1,
  160. e: 3,
  161. g: 1,
  162. l: 2,
  163. m: 1,
  164. n: 2,
  165. r: 1,
  166. s: 2,
  167. y: 2
  168. }
  169.  
  170. */
  171.  
  172. function characterCounts(stringToCount) {
  173. // CODE HERE
  174. }
  175.  
  176.  
  177. // Bonus 7
  178. /**
  179. * @func numberOfArguments
  180. * @desc Takes any number of arguments, returns how many were passed
  181. * @param {*} arg
  182. * @returns {Number} the number of arguments passed to the function
  183. * @example
  184. > numberOfArguments(6, 3, 8, 2, 'bar', 'foo')
  185. => 6
  186.  
  187. > numberOfArguments()
  188. => 0
  189. */
  190.  
  191. function numberOfArguments() {
  192. // CODE HERE
  193. }
  194.  
  195.  
  196. /* ******* */
  197. return {
  198. characterCounts,
  199. filterLongWords,
  200. findLongestWord,
  201. isCharacterAVowel,
  202. maxOfThree,
  203. maxOfTwoNumbers,
  204. multiplyArray,
  205. numberOfArguments,
  206. reverseString,
  207. sumArray,
  208. };
  209. })();
  210.  
  211.  
  212. if ((typeof module) !== 'undefined') {
  213. module.exports = jsFunctionsLab;
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement