Skip to content

Commit 289b01c

Browse files
authored
Merge pull request vJechsmayr#51 from Quadriphobs1/refactor/folder-structure
Refactor Folder Structure and Palindrome Solution
2 parents fb79f1b + 55fe590 commit 289b01c

5 files changed

Lines changed: 3171 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
.DS_Store
9+
**/*/.DS_Store
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# nyc test coverage
18+
.nyc_output
19+
20+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21+
.grunt
22+
23+
# Bower dependency directory (https://bower.io/)
24+
bower_components
25+
26+
# node-waf configuration
27+
.lock-wscript
28+
29+
# Dependency directories
30+
node_modules/
31+
jspm_packages/
32+
33+
# Optional npm cache directory
34+
.npm
35+
36+
37+
# Yarn Integrity file
38+
.yarn-integrity
39+
40+
# vscode
41+
.vscode/

‎package.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "javascriptalgorithms",
3+
"version": "0.0.0",
4+
"description": "All algorithms implemented in JavaScript (for education) There implementations are for learning purposes. If you want to contribute more efficient solutions feel free to open an issue and commit your solution.",
5+
"scripts": {
6+
"test": "jest"
7+
},
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/vJechsmayr/JavaScriptAlgorithms.git"
11+
},
12+
"author": "",
13+
"license": "ISC",
14+
"bugs": {
15+
"url": "https://github.com/vJechsmayr/JavaScriptAlgorithms/issues"
16+
},
17+
"homepage": "https://github.com/vJechsmayr/JavaScriptAlgorithms#readme",
18+
"devDependencies": {
19+
"jest": "^24.9.0"
20+
}
21+
}

‎palindrome/palindrome.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function isPalindromeRecursive(chars, s, e) {
2+
if (s === e) {
3+
return true;
4+
}
5+
6+
if (chars[s] !== chars[e]) {
7+
return false;
8+
}
9+
10+
if (s < e + 1) {
11+
return isPalindromeRecursive(chars, s + 1, e - 1)
12+
}
13+
14+
return true;
15+
}
16+
17+
function isPalindrome(s) {
18+
// convert the input to string
19+
const chars = String(s);
20+
const len = chars.length
21+
if (len <= 1) {
22+
return true
23+
}
24+
return isPalindromeRecursive(chars, 0, len - 1);
25+
}
26+
27+
module.exports = isPalindrome;

‎palindrome/palindrome.test.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const isPalindrome = require('./palindrome');
2+
3+
describe('isPalindrome()', () => {
4+
it('should return true for single number', () => {
5+
expect(isPalindrome(1)).toBeTruthy();
6+
})
7+
8+
it('should return true for valid number "121"', () => {
9+
expect(isPalindrome(121)).toBeTruthy();
10+
})
11+
12+
it('should return true for same number 111', () => {
13+
expect(isPalindrome(111)).toBeTruthy();
14+
})
15+
it('should return false for invalid number', () => {
16+
expect(isPalindrome(123)).toBeFalsy();
17+
})
18+
19+
it('should return true for long value', () => {
20+
expect(isPalindrome(123321123321)).toBeTruthy();
21+
})
22+
})

0 commit comments

Comments
 (0)