Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////DOM VERSION////////////////////////////////
  2. // Returns content processed for palindrome testing
  3. let processedContent = content => content.toLowerCase();
  4.  
  5. // Reverses a string
  6. let reverse = content => Array.from(content).reverse().join("");
  7.  
  8. // Defines a Phrase object
  9. function Phrase() {
  10.   this.content = arguments[0];
  11.   this.arguments = arguments;
  12.   this.argumentsArray = [...arguments];
  13.  
  14.   // Returns true if the phrase is a palindrome, false otherwise
  15.   this.palindrome = () => {
  16.     if(this.arguments.length === 1) {
  17.          // Intermediate Assignment
  18.         this.firstIndex = processedContent(this.content);
  19.         return this.firstIndex === reverse(this.firstIndex);
  20.     } else {
  21.         // Intermediate Assignment
  22.         this.nthIndex =
  23.       processedContent(this.arguments[Number(prompt("Enter Index of argument to be palindromized eg 1 for second index"))]);
  24.         return this.nthIndex === reverse(this.nthIndex);
  25.     }
  26.   }
  27.  
  28.   // Makes the phrase LOUDER
  29.   this.louder = () => this.argumentsArray.map(eachEntry => {
  30.     console.log(eachEntry.toUpperCase());
  31.     return eachEntry.toUpperCase();
  32.     })
  33. }
  34. // Defines a TranslatedPhrase object
  35. function TranslatedPhrase() {
  36.   this.content = arguments[0];
  37.   this.arguments = arguments;
  38.   this.argumentsArray = [...arguments];
  39.   Phrase.apply(this, this.argumentsArray);
  40. }
  41.  
  42. TranslatedPhrase.prototype = Object.create(Phrase.prototype);
  43. console.log(TranslatedPhrase.prototype);
  44.  
  45. TranslatedPhrase.prototype.constructor = TranslatedPhrase;
  46. console.log(TranslatedPhrase.prototype);
  47. /////END OF DOM VERSION ///////
  48. /*
  49. After running the code above in the console, the focus is especially on the palindrome() method,
  50. eg,
  51. let exciting = new Phrase("ade", "nurudeen", "aye", "great", "awa", "naughty");
  52. On calling the palindrome() method; exciting.palindrome();
  53. Inputting '4' for example would return true, while inputting "3" for example would return false
  54.  
  55. So, my challenge has been how to simply replace prompt in the node CLI implementation
  56. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement