- Practice algorithmic problem solving
Given an Array of strings, return the shortest string. If there is more than one string of that length, return the string that comes first in the list. The Array will have a minimum length of 1.
Input: ['aaa', 'a', 'bb', 'ccc']
Output: 'a'
Input: ['cat', 'hi', 'dog', 'an']
Output: 'hi'
Input: ['flower', 'juniper', 'lily', 'dandelion']
Output: 'lily'
Use the language of your choosing. We've included starter files for some languages where you can pseudocode, explain your solution and code.
For this task, we are also asking you to calculate the average runtime of your solution. In other words, you run it a bunch of times and then divide the total time it took for the solution to run by the number of times it ran.
Here is the pseudocode for creating your own basic benchmarking procedure:
store the current time in a variable called start time
loop 1000 times:
execute the method using a small input, e.g. three items if input is an Array
execute the method using a larger input, e.g. 100 items if input is an Array
average runtime = (current time - start time) / 2000
- Rewrite the problem in your own words
- Validate that you understand the problem
- Write your own test cases
- Pseudocode
- Code!
And remember, don't run our tests until you've passed your own!
cd
into the ruby folderruby <filename>.rb
cd
into the javascript foldernode <filename>.js
cd
into the ruby folderbundle install
rspec
cd
into the javascript foldernpm i
npm test