-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d82d476
commit 7196bca
Showing
8 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n Divisor of Strings/gcdOfStrings.spec.ts → ...n Divisor of Strings/gcdOfStrings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Number of Candies/kidsWithCandies.spec.ts → ...Number of Candies/kidsWithCandies.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ings Alternately/mergeAlternately.spec.ts → ...ings Alternately/mergeAlternately.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/page-2/151. Reverse Words in a String/reverseWords.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { reverseWords } from './reverseWords'; | ||
|
||
describe('151. Reverse Words in a String', () => { | ||
test('reverseWords', () => { | ||
expect(reverseWords('the sky is blue')).toBe('blue is sky the'); | ||
expect(reverseWords(' hello world ')).toBe('world hello'); | ||
expect(reverseWords('a good example')).toBe('example good a'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type ReverseWords = (s: string) => string; | ||
|
||
/** | ||
* Accepted | ||
*/ | ||
export const reverseWords: ReverseWords = (s) => { | ||
// Trim leading and trailing spaces | ||
const trimmed = s.trim(); | ||
|
||
// Split the string by spaces to get an array of words | ||
const words = trimmed.split(/\s+/).filter((word) => word.length > 0); | ||
|
||
// Reverse the array of words | ||
const reversedWords = words.reverse(); | ||
|
||
// Join the reversed array into a string with a single space separator | ||
return reversedWords.join(' '); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...Can Place Flowers/canPlaceFlowers.spec.ts → ...Can Place Flowers/canPlaceFlowers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters