Basic Scipting Algorithms

Reverse a String

Reverse the provided string.

You may need to turn the string into an array before you can reverse it.

Your result must be a string.

Remember to use Read-Search-Ask if you get stuck. Write your own code.

Concepts:

  • Global String Object
  • String.split()
  • Array.reverse()
  • Array.join()

Harder Test Data:

Greetings from Earth

RESULTS:

Factorialize a Number

Return the factorial of the provided integer.

If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120

Concepts:

  • Arithmetic Operators

Harder Test Data:

20

RESULTS:

Check for Palindromes

Return true if the given string is a palindrome. Otherwise, return false.

A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

Note:
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.

We'll pass strings with varying formats, such as "racecar", "RaceCar", and"race CAR" among others.

Concepts:

  • String.replace()
  • String.toLowerCase()

Harder Test Data:

A man, a plan, a canal. Panama

RESULTS:

Find the Longest Word in a String

Return the length of the longest word in the provided sentence.

Your response should be a number.

Concepts:

  • String.split()
  • String.length

Harder Test Data:

The quick brown fox jumped over the lazy dog

RESULTS:

Title Case a Sentence

Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.

For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".

Concepts:

  • String.split()

Harder Test Data:

HERE IS MY HANDLE HERE IS MY SPOUT

RESULTS:

Return Largest Numbers in Arrays

Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays.

Remember, you can iterate through an array with a simple for loop, and access each member with array syntax arr[i].

Concepts:

  • Comparison Operators

Harder Test Data:

RESULTS: