javascript-vs-ruby

A comparison between Ruby and JavaScript is presented for a range of problems and data types. Flick between the .rb and .js to compare what is similar and what is different between the two languages.

You can run the Ruby ones using ruby 1.rb. You can run the JavaScript ones using node 1.js.

Challenges

  1. Look at the X.rb file, and write a new X.copy.js from scratch. Use the given X.js file as a reference
  2. Do the challenges from the readme.md in Ruby first
  3. Then do them in JavaScript

1.rb / 1.js

  1. Create variables for Anzac Day, and output them
  2. Change your code to use the Date class
  • Ruby hint: Date.new(…)
  • JavaScript hint: new Date(…)

2.rb / 2.js

  1. Convert the lengths to yards using .each (.rb) / .forEach (.js), and output them
  2. Convert the lengths to yards using .map (.rb) / .map (.js), and output them
  3. Find the longest fish, and output it
  4. Create a sorted copy of the centimetre lengths array, and output it
  5. Find average fish length in centimetres

3.rb / 3.js

  1. Add another three movies
  2. Add a property for director to each movie, and display it
  3. Convert people from being strings (Tom Hanks) to objects (with e.g. first & last name)

4.rb / 4.js

  1. Skip conjuctions (and / or / the / of) from wordFrequencyTable function
  2. Skip conjuctions (and / or / the / of) from wordCount function
  3. Change the sentence to the "It was the best of times…" chapter 1 excerpt from here: https://en.wikiquote.org/wiki/A_Tale_of_Two_Cities
  4. Find the five most popular words using the result of wordFrequencyTable

5.rb / 5.js

  1. Add a removeItem(item) method
  2. Add a sortItems() method to sort alphabetically

6.rb / 6.js

  1. Contrast the differences between 6.js and 6b.js. They both have the same effect, but work differently. 6.js is a more literal translation from 6.rb. Write down everything you see different about the two JavaScript versions.

7.rb / 7.js

  1. Work out the date in 100 days, and display it
  2. Work out the date 1000 days ago in the past, and display it

8.rb / 8.js

  1. Display 'The 80s ruled' in yellow text on magenta background.
  2. Display 'RGB' with each letter in its color on a black background
  3. Display 'CMYK' with each letter in its color on a white background