Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////DOM VERSION////////////////////////////////
- // Returns content processed for palindrome testing
- let processedContent = content => content.toLowerCase();
- // Reverses a string
- let reverse = content => Array.from(content).reverse().join("");
- // Defines a Phrase object
- function Phrase() {
- this.content = arguments[0];
- this.arguments = arguments;
- this.argumentsArray = [...arguments];
- // Returns true if the phrase is a palindrome, false otherwise
- this.palindrome = () => {
- if(this.arguments.length === 1) {
- // Intermediate Assignment
- this.firstIndex = processedContent(this.content);
- return this.firstIndex === reverse(this.firstIndex);
- } else {
- // Intermediate Assignment
- this.nthIndex =
- processedContent(this.arguments[Number(prompt("Enter Index of argument to be palindromized eg 1 for second index"))]);
- return this.nthIndex === reverse(this.nthIndex);
- }
- }
- // Makes the phrase LOUDER
- this.louder = () => this.argumentsArray.map(eachEntry => {
- console.log(eachEntry.toUpperCase());
- return eachEntry.toUpperCase();
- })
- }
- // Defines a TranslatedPhrase object
- function TranslatedPhrase() {
- this.content = arguments[0];
- this.arguments = arguments;
- this.argumentsArray = [...arguments];
- Phrase.apply(this, this.argumentsArray);
- }
- TranslatedPhrase.prototype = Object.create(Phrase.prototype);
- console.log(TranslatedPhrase.prototype);
- TranslatedPhrase.prototype.constructor = TranslatedPhrase;
- console.log(TranslatedPhrase.prototype);
- /////END OF DOM VERSION ///////
- /*
- After running the code above in the console, the focus is especially on the palindrome() method,
- eg,
- let exciting = new Phrase("ade", "nurudeen", "aye", "great", "awa", "naughty");
- On calling the palindrome() method; exciting.palindrome();
- Inputting '4' for example would return true, while inputting "3" for example would return false
- So, my challenge has been how to simply replace prompt in the node CLI implementation
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement