Skip to content

Instantly share code, notes, and snippets.

@oampo
Last active November 29, 2016 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oampo/3146f1d0a3e03fabfca4b5f081168f17 to your computer and use it in GitHub Desktop.
Save oampo/3146f1d0a3e03fabfca4b5f081168f17 to your computer and use it in GitHub Desktop.

String, number, and logic drills

Jedi name

Write a function called jediName which takes two arguments:

  • firstName - a person's first name
  • lastName - a person's last name

The function should return the person's Jedi name. A Jedi name is formed from the first three letters of the last name, and the first two letters of the first name. For example, jediName('Beyonce', 'Knowles') should return 'KnoBe'.

To infinity...

Write a function called beyond which takes a single argument, num and logs a different message depending on its value.

  • If num is infinite (either positive or negative) it should log out 'And beyond'.
  • If num is finite and positive it should log out 'To infinity'.
  • If num is finite and negative it should log out 'To negative infinity'.
  • If num is zero it should log out 'Staying home'.

Cracking the code

A code has been invented which replaces each character in a sentence with a five letter word. The first letter of each encoded word determines which of the remaining four characters contains the decoded character according to this table:

First letter Character number
a 2
b 3
c 4
d 5

So for example, the encoded word 'cycle' would be decoded to the character 'l'. This is because the first letter is a 'c', so you look for the fourth character, which is 'l'.

If the first letter of the encoded word isn't 'a', 'b', 'c', or 'd' (for example 'mouse') this should be decoded to a space.

Write a function called decode which takes an encoded word as an argument, and returns the correct decoded character.

Use your function to decode the following message: 'craft block argon meter bells brown croon droop'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment