Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. function InputError(message){
  2. this.message = message;
  3. this.stack = (new Error()).stack;
  4.  
  5. }
  6.  
  7. var regex1 = /(\w\W)+/;
  8. var regex2 = /^[a-zA-Z0-9_$]$/g;
  9. var nregex2 = /[^a-zA-Z0-9_$]-?/g;
  10. var regex4 = new RegExp("\\b(" + word + ")\\b" , "gi");
  11. var regex5 = /^[a-zA-Z0-9_.-]@mailbox.tu-berlin.de$/gi;
  12.  
  13. function getCharacterCount (text) {
  14.  
  15. if(text.test(regex1)){
  16. return text.length;
  17. }
  18. else {
  19. return 0;
  20. }
  21. }
  22.  
  23. function getWords (text) {
  24. if(text.test(regex1) && text.test(regex2)){
  25. return text.split(nregex2);
  26. } else {
  27. return [];
  28. }
  29. }
  30.  
  31. function getLongestWords (text) {
  32. var array = text.getWords();
  33. var result = [];
  34. if (array.length > 0){
  35. for(var i = 0; i<array.length; i++){
  36. if (result[0].length <= array[i].length){
  37. result.push(array[i]);
  38. }
  39. }
  40. return result;
  41. } else {
  42. return [];
  43. }
  44. }
  45.  
  46. function getWordFrequency (text) {
  47. var word;
  48. var result = [];
  49. var array = text.getWords();
  50. if (array.length > 0){
  51. for(var i = 0; i<array.length; i++){
  52. var count = 0;
  53. word = array[i];
  54. for(var i = 0; i<array.length; i++){
  55. if(array[i].test(regex4)){
  56. count++;
  57. }
  58. }
  59. result.push(word + ":" + count);
  60. };
  61. return result;
  62. } else {
  63. return {};
  64. }
  65.  
  66. }
  67.  
  68. function filterTUBMails (text) {
  69. if(text.test(regex1)){
  70. var array = text.split(" ");
  71. var result = array.filter(word => regex5);
  72. return result;
  73. } else {
  74. return [];
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement