Skip to content

Commit 8644d43

Browse files
committed
test: add small palindrome case
1 parent 214669b commit 8644d43

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

src/interview-classics/is-palindrome/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ consider the followihg whitespace characters for this exercise
1717
* `tab`
1818
* `new line`
1919

20-
## Function Signagure
20+
## Function Signature
2121

2222
```typescript
2323
function isPalindrome(str: string): boolean
@@ -46,3 +46,8 @@ Out: true
4646
```
4747
4848
## Optimizations
49+
50+
Instead of creating a reversed and normalized string, you can use a loop to
51+
compare the first character to the last character, then the second character to
52+
the next-to-last character, and so on. This lowers the space complexity from
53+
linear to constant.

src/interview-classics/is-palindrome/is-pal-while-regex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ const isPalindrome = (str) => {
4141

4242
module.exports = {
4343
fun: isPalindrome,
44-
id: 'while-loop regex'
44+
id: 'while-loop inclusive-regex'
4545
}

src/interview-classics/is-palindrome/is-pal.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const { readFileSync } = require('fs')
55

66
const solutions = require('./is-pal.repo')
77

8-
const bigPalPath = join(__dirname, '/big-palindrome.txt')
9-
const bigPalindrome = readFileSync(bigPalPath, 'utf-8')
8+
const smallPalPath = join(__dirname, '/palindrome-small.txt')
9+
const bigPalPath = join(__dirname, '/palindrome-big.txt')
1010

11-
const smallPalindrome = `Anita! LAva :
12-
la?; tina.`
11+
const smallPalindrome = readFileSync(smallPalPath, 'utf-8')
12+
const bigPalindrome = readFileSync(bigPalPath, 'utf-8')
1313

1414
solutions.forEach(({ fun, id }) => {
1515
describe(`Palindrome test algorithm "${id}"`, () => {

src/interview-classics/is-palindrome/is-pal.time.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ const { readFileSync } = require('fs')
44
const { timeAndReport } = require('../../../lib/time')
55
const solutions = require('./is-pal.repo')
66

7-
const bigPalPath = join(__dirname, '/big-palindrome.txt')
7+
const smallPalPath = join(__dirname, 'palindrome-small.txt')
8+
const bigPalPath = join(__dirname, '/palindrome-big.txt')
9+
10+
const emptyPalindrome = ''
11+
const smallPalindrome = readFileSync(smallPalPath, 'utf-8')
812
const bigPalindrome = readFileSync(bigPalPath, 'utf-8')
913

10-
const args = [bigPalindrome]
11-
const runs = 10_000
14+
const emptyArgs = [emptyPalindrome]
15+
const emptyRuns = 1_000_000
16+
17+
const smallArgs = [smallPalindrome]
18+
const smallRuns = 100_000
19+
20+
const bigArgs = [bigPalindrome]
21+
const bigRuns = 10_000
1222

13-
timeAndReport(solutions, args, runs, 'Is palindrome?')
23+
timeAndReport(solutions, emptyArgs, emptyRuns, 'is-palindrome (empty)')
24+
timeAndReport(solutions, smallArgs, smallRuns, 'is-palindrome (small)')
25+
timeAndReport(solutions, bigArgs, bigRuns, 'is-palindrome (big)')
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Doc, note:
2+
3+
I dissent!
4+
5+
A fast never prevents a fatness;
6+
7+
I diet on cod?

0 commit comments

Comments
 (0)