Coder Social home page Coder Social logo

js-tweet-shortener-v-000's Introduction

Tweet Shortener

Instead of using prototypes and constructors in this lab, we'll be using a javascript object with functions attached. (You'll sometimes hear this referred to as "object literal" notation, because it uses an object โ€” literally.)

In Ruby, modules can be used to hold methods that act on the values passed to it, and nothing else.

module StringFancifier
  def self.make_fancy(string)
    "<*-~/#{string}/~=*>"
  end
end

.make_fancy only knows about the argument passed, and has no internal state.

In lib/tweetShortener.js, you'll see:

var tweetShortener = {
    wordSubstituter: function(){},
    bulkShortener: function(){},
    selectiveShortener: function(){},
    shortenedTruncator: function(){},
};

This would look something like the following in ruby:

module TweetShortener
  def self.word_substituter; end
  def self.bulk_shortener; end
  def self.selective_shortener; end
  def self.shortened_truncator; end
end

On we go.

Instructions

A client has hired you to automatically post some of their brand messages to twitter, but the problem is that some of the tweets are too long. Your job is to automatically shorten them by replacing longer words with shorter representations (i.e. "two" becomes "2").

You'll want to write a method that will take a tweet, search it for words that you can substitute, and return a substituted string tweet. For instance, the tweet "Hello to you, I'm at home" would become "Hi 2 u, I'm @ home". The client has provided the following acceptable substitutes.

"hello" becomes 'hi'
"to, two, too" become '2'
"for, four" become '4'
'be' becomes 'b'
'you' becomes 'u'
"at" becomes "@"
"and" becomes "&"

and here is the list of tweets:

  1. "Hey guys, can anyone teach me how to be cool? I really want to be the best at everything, you know what I mean? Tweeting is super fun you guys!!!!"
  1. "OMG you guys, you won't believe how sweet my kitten is. My kitten is like super cuddly and too cute to be believed right?"
  1. "I'm running out of example tweets for you guys, which is weird, because I'm a writer and this is just writing and I tweet all day. For real, you guys. For real."
  1. "GUISEEEEE this is so fun! I'm tweeting for you guys and this tweet is SOOOO long it's gonna be way more than you would think twitter can handle, so shorten it up you know what I mean? I just can never tell how long to keep typing!"
  1. "New game. Middle aged tweet followed by #youngPeopleHashTag Example: Gotta get my colonoscopy and mammogram soon. Prevention is key! #swag"
  1. Write a method to shorten a string based on the allowed substitutes

  2. Write a method that iterates over the list of tweets, shortens them, and returns a new array with the shortened tweets

hint: you'll need a way to look up each word and see if it has a substitution

Now the client has come back to you. They love the program, but they noticed that even tweets that are under 140 characters are being shortened. Now they want you to only shorten the tweet if it's too long.

  1. Write a new method that only does the substitutions if the tweet is longer than 140 characters. If the tweet is 140 characters or shorter, just return the original tweet.

Things are going great, but you're noticing that some tweets are too long still, even after substituting shorter words. Being the conscientious developer that you are, you talk to the client about this scenario and decide together that the best thing to do is just truncate the string to 140 characters if it's still too long after you do the substitution.

  1. Write another method that truncates the tweet to 140 characters with an ellipsis if it's still too long after substitution. E.g. "Random Passage satisfies the craving for those details that ..."

To run the specs follow these commands:

# first install the new gem to run the tests
gem sources -a http://flatiron:[email protected]
gem install learn-co

# to run in the command line run
learn

#to run in the browser
learn -b

View Tweet Shortener on Learn.co and start learning to code for free.

js-tweet-shortener-v-000's People

Contributors

annjohn avatar blake41 avatar deniznida avatar fislabstest avatar fs-lms-test-bot avatar gj avatar kthffmn avatar octosteve avatar pletcher avatar sarogers avatar tsiege avatar vinnyalfieri avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.