Advertisement
Guest User

Untitled

a guest
May 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. import { Component, OnInit } from "@angular/core";
  2. import { FormBuilder, FormGroup } from "@angular/forms";
  3.  
  4. @Component({
  5. selector: "app-words",
  6. templateUrl: "./words.component.html",
  7. styleUrls: ["./words.component.scss"]
  8. })
  9. export class WordsComponent implements OnInit {
  10. extraBeer = [
  11. "cascade",
  12. "nugget",
  13. "chinook",
  14. "citra",
  15. "hallertauer",
  16. "willamette",
  17. "brettanomyces",
  18. "Saccharomyces",
  19. "Wyeast",
  20. "Well balanced. Ferments dry, finishes soft",
  21. "Slightly nutty, soft, clean and tart finish",
  22. "Clean flavors accentuate hops; very versatile",
  23. "A blend of ale and lager strains that creates a clean, crisp, light American lager style",
  24. "A malty, complex profile that clears well",
  25. "Develops estery and somewhat peppery spiceyness"
  26. ];
  27.  
  28. extraFunk = ["more funk", "MORE FUNK!!!"];
  29.  
  30. words = [
  31. "hops",
  32. "hippy",
  33. "hipster",
  34. "pot",
  35. "hemp",
  36. "moog",
  37. "at the Wedge",
  38. "drinking beer",
  39. "brewing",
  40. "in pack square",
  41. "AB Tech",
  42. "stay weird",
  43. "goth",
  44. "at the Orange Peel",
  45. "green man",
  46. "at the grove park",
  47. "on patton",
  48. "in Montford",
  49. "farm-to-table",
  50. "smoking weed",
  51. "puffing on pot",
  52. "with dreads",
  53. "hemp",
  54. "moog",
  55. "brewing",
  56. "at pack square",
  57. "at AB Tech",
  58. "at UNCA",
  59. "at Biltmore",
  60. "foody",
  61. "when in Sandy Mush",
  62. "when at Leicester",
  63. "while walking in the River Arts District",
  64. "poet for hire",
  65. "keeping it weird",
  66. "Bascom Lamar Lunsford",
  67. "12 Bones",
  68. "Spoon Lady",
  69. "riding inLaZoom",
  70. "eat local",
  71. "drink local",
  72. "flat iron building",
  73. "in the mountains",
  74. "pisgah",
  75. "pale ale",
  76. "in West Asheville",
  77. "French Broad",
  78. "Subaru",
  79. "bumper stickers",
  80. "a girl with hairy arm pits",
  81. "a girl with hairy legs",
  82. "a hipster with a bun",
  83. "with smelly pits",
  84. "drum circle",
  85. "eating hippy food",
  86. "dude with a man bun"
  87. ];
  88.  
  89. randoWords = "";
  90. randomNumber = 1;
  91. arr: string[];
  92. registerForm: FormGroup;
  93. paragraphs = [];
  94.  
  95. constructor(private formBuilder: FormBuilder) {}
  96.  
  97. ngOnInit() {
  98. this.registerForm = this.formBuilder.group({
  99. numberOfWords: "50",
  100. numberOfParagraphs: "1",
  101. moreBeer: false,
  102. moreFunk: false
  103. });
  104. }
  105.  
  106. onSubmit() {
  107. //update array based on the number of paragraphs user selects
  108. this.paragraphs.length = this.registerForm.value.numberOfParagraphs;
  109. //loop through array and run getNumberOfWords for each element
  110. for (var i = 0; i < this.paragraphs.length; i++) {
  111. this.paragraphs[i] = this.getNumberOfWords();
  112. }
  113. if (this.registerForm.value.moreBeer == true) {
  114. this.getMoreBeer(this.paragraphs.length);
  115. }
  116. if (this.registerForm.value.moreFunk == true) {
  117. this.getMoreFunk();
  118. }
  119. }
  120.  
  121. getMoreBeer(numParagraphs) {
  122. console.log("made to getMoreBeer", numParagraphs);
  123. // for (var i = 0; i < numParagraphs.length; i++) {
  124. // // numberOfParagraphs[i] = this.getNumberOfWords();
  125. // console.log("in for loop");
  126. // }
  127. }
  128.  
  129. getMoreFunk() {
  130. let wordsPlusFunk = this.paragraphs.map(
  131. paragraph => paragraph + this.extraFunk
  132. );
  133. this.paragraphs = wordsPlusFunk;
  134. }
  135.  
  136. getNumberOfWords() {
  137. let words;
  138. const shuffledWords = [...this.words]; //make a copy of the array to prevent mutation
  139. shuffledWords.sort(() => 0.5 - Math.random());
  140. this.randomlyInsertPeriods(shuffledWords);
  141. words = shuffledWords
  142. .slice(0, this.registerForm.value.numberOfWords)
  143. .join(" ");
  144. words = this.capitalizeFirstLetter(words);
  145. words = this.addPeriod(words);
  146. return words;
  147. }
  148.  
  149. capitalizeFirstLetter(string) {
  150. return string.charAt(0).toUpperCase() + string.slice(1);
  151. }
  152.  
  153. getRandomNumber(min, max) {
  154. return Math.floor(Math.random() * (max - min + 1)) + min;
  155. }
  156.  
  157. randomlyInsertPeriods(words) {
  158. var arrayLength = this.words.length;
  159. this.randomNumber = this.getRandomNumber(3, 10);
  160. for (var i = 0; i < arrayLength; i++) {
  161. //inserts a period based on the randomNumber from above and also
  162. //capitalizes the word after the period
  163. if ((i + 1) % this.randomNumber == 0) {
  164. words.splice(i, 0, ".");
  165. words.splice(i + 1, 1, this.capitalizeFirstLetter(words[i + 1]));
  166. }
  167. }
  168. return words;
  169. }
  170.  
  171. incrementParagraphs() {
  172. let paragraphs = Number(this.registerForm.value.numberOfParagraphs);
  173. paragraphs += 1;
  174. this.registerForm.get("numberOfParagraphs").setValue(paragraphs);
  175. }
  176.  
  177. decrementParagraphs() {
  178. let paragraphs = Number(this.registerForm.value.numberOfParagraphs);
  179. paragraphs -= 1;
  180. this.registerForm.get("numberOfParagraphs").setValue(paragraphs);
  181. }
  182.  
  183. addPeriod(words) {
  184. return words + ".";
  185. }
  186. addperiod(words) {
  187. // add a period to end of words
  188. return (words = words + ".");
  189. // console.log("test for add words", words);
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement