File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11function getOrdinalNumber ( num ) {
2- if ( num % 10 === 1 && num % 100 !== 11 ) {
3- return num + "st" ;
2+ if ( num % 100 >= 11 && num % 100 <= 13 ) {
3+ return num + "th" ;
44 }
5+
6+ if ( num % 10 === 1 ) {
7+ return num + "st" ;
8+ }
9+
10+ if ( num % 10 === 2 ) {
11+ return num + "nd" ;
12+ }
13+
14+ if ( num % 10 === 3 ) {
15+ return num + "rd" ;
16+ }
17+
18+ return num + "th" ;
519}
620
721module . exports = getOrdinalNumber ;
Original file line number Diff line number Diff line change @@ -14,7 +14,19 @@ const getOrdinalNumber = require("./get-ordinal-number");
1414// When the number ends with 1, except those ending with 11,
1515// Then the function should return a string by appending "st" to the number.
1616test ( "should append 'st' for numbers ending with 1, except those ending with 11" , ( ) => {
17- expect ( getOrdinalNumber ( 1 ) ) . toEqual ( "1st" ) ;
17+ expect ( getOrdinalNumber ( 1 ) ) . toEqual ( "1st" ) ;
18+ expect ( getOrdinalNumber ( 2 ) ) . toEqual ( "2nd" ) ;
19+ expect ( getOrdinalNumber ( 3 ) ) . toEqual ( "3rd" ) ;
20+ expect ( getOrdinalNumber ( 4 ) ) . toEqual ( "4th" ) ;
21+
22+ expect ( getOrdinalNumber ( 11 ) ) . toEqual ( "11th" ) ;
23+ expect ( getOrdinalNumber ( 12 ) ) . toEqual ( "12th" ) ;
24+ expect ( getOrdinalNumber ( 13 ) ) . toEqual ( "13th" ) ;
25+
1826 expect ( getOrdinalNumber ( 21 ) ) . toEqual ( "21st" ) ;
19- expect ( getOrdinalNumber ( 131 ) ) . toEqual ( "131st" ) ;
27+ expect ( getOrdinalNumber ( 22 ) ) . toEqual ( "22nd" ) ;
28+ expect ( getOrdinalNumber ( 23 ) ) . toEqual ( "23rd" ) ;
29+ expect ( getOrdinalNumber ( 24 ) ) . toEqual ( "24th" ) ;
2030} ) ;
31+
32+ // 
Original file line number Diff line number Diff line change 1- function repeatStr ( ) {
2- // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat).
3- // The goal is to re-implement that function, not to use it.
4- return "hellohellohello" ;
5- }
1+ function repeatStr ( str , count ) {
2+ if ( count < 0 ) {
3+ throw new Error ( "Count must be a non-negative integer" ) ;
4+ } else if ( count === 0 ) {
5+ return "" ;
6+ } else {
7+ return str . repeat ( count ) ;
8+ }
9+ }
610
711module . exports = repeatStr ;
Original file line number Diff line number Diff line change 11// Implement a function repeatStr
2-
2+ const repeatStr = require ( "./repeat-str" ) ;
33// Given a target string `str` and a positive integer `count`,
44// When the repeatStr function is called with these inputs,
55// Then it should:
99// When the repeatStr function is called with these inputs,
1010// Then it should return a string that contains the original `str` repeated `count` times.
1111
12- function repeatStr ( str , count ) {
13- if ( count < 0 ) {
14- throw new Error ( "Count must be a non-negative integer" ) ;
15- } else if ( count === 0 ) {
16- return "" ;
17- } else {
18- return str . repeat ( count ) ;
19- }
20- }
12+
2113
2214test ( "should repeat the string count times" , ( ) => {
2315 const str = "hello" ;
You can’t perform that action at this time.
0 commit comments