6 kyu

Ordinal Numbers

962 of 1,371wthit56

Description:

Introduction

Ordinal numbers are used to tell the position of something in a list. Unlike regular numbers, they have a special suffix added to the end of them.

Task

Your task is to write the ordinal(number, brief) function. number will be an integer. You need to find the ordinal suffix of said number.

brief is an optional parameter and defaults to false. When using brief notation, nd and rd use d instead. All others are the same.

ordinal(number, brief) should return a string containing those two characters (or one character) that would be tagged onto the end of the number.

The last two digits determine the ordinal suffix.

Notation for general notation

0  1  2  3  4  5  6  7  8  9
th st nd rd th th th th th th

Notation for brief notation

0  1  2  3  4  5  6  7  8  9
th st d  d th th th th th th

However, when the last two digits of the number are 11, 12, or 13, th is used instead of st,nd,rd respectively.

Examples

*General
1 - 1st
2 - 2nd
3 - 3rd
5 - 5th
11- 11th
149 - 149th
903 - 903rd
*Brief
1 - 1st
2 - 2d
3 - 3d
5 - 5th
11- 11th
149 - 149th
903 - 903d

Notes

  • Numbers might be passed in replacement of booleans, so false may be passed in as 0 and true may be passed in as 1.
Strings
Algorithms

Stats:

CreatedJan 20, 2014
PublishedJan 20, 2014
Warriors Trained2777
Total Skips432
Total Code Submissions5974
Total Times Completed1371
JavaScript Completions962
C# Completions114
Python Completions328
COBOL Completions3
Total Stars33
% of votes with a positive feedback rating93% of 227
Total "Very Satisfied" Votes197
Total "Somewhat Satisfied" Votes27
Total "Not Satisfied" Votes3
Total Rank Assessments28
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • wthit56 Avatar
  • jhoffner Avatar
  • suic Avatar
  • user5036852 Avatar
  • hobovsky Avatar
  • WestwardLand968 Avatar
  • akar-0 Avatar
Ad