Skip to content

Upgraded Algorithm of alpha numeric palindrome #1006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
72def41
feat: improved memoize function
fahimfaisaal Mar 2, 2022
8548ef1
docs: modified documentation
fahimfaisaal Mar 2, 2022
ce9d3b9
style: format with standard
fahimfaisaal Mar 2, 2022
1e2fb53
docs: modified stringify doc
fahimfaisaal Mar 2, 2022
2a5c28b
refactor: remove two repetition implementation
fahimfaisaal Mar 2, 2022
c582f58
feat: added validation, test codes
fahimfaisaal Mar 14, 2022
cdff0e3
chore: remove useless words
fahimfaisaal Mar 15, 2022
5727b64
feat: added types for jest
fahimfaisaal Mar 15, 2022
025a8b8
Merge branch 'upgrade-abs' of https://github.com/fahimfaisaal/Javascr…
fahimfaisaal Mar 15, 2022
9efda24
chore: added link box
fahimfaisaal Mar 15, 2022
98ffd1d
feat: added new validation test casses & methods
fahimfaisaal Mar 26, 2022
b8d6e68
style: formated with standard
fahimfaisaal Mar 26, 2022
b7c961c
feat: added parse method & test cases
fahimfaisaal Mar 26, 2022
6b7b715
docs: added js docs
fahimfaisaal Mar 27, 2022
269a3f4
chore: added default import export
fahimfaisaal Mar 27, 2022
5cedaa9
feat: imporved algorithm via replace method
fahimfaisaal Mar 27, 2022
d00a7bf
test: added two test cases
fahimfaisaal Mar 27, 2022
bbcce39
feat: added jest type for suggestions
fahimfaisaal Mar 28, 2022
9be30a8
feat: added `reduceRight` & `trim` method
fahimfaisaal Mar 28, 2022
489544d
chore: added helper variable
fahimfaisaal Mar 28, 2022
68cb5ad
feat: added new rotation option
fahimfaisaal Mar 29, 2022
addf721
Revert "chore: added helper variable"
fahimfaisaal Mar 29, 2022
07a2b17
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal Mar 29, 2022
8c297ae
Merge branch 'upgrade-CaesarsCipher'
fahimfaisaal Mar 29, 2022
605cfb7
Merge branch 'upgrade-reverseWord'
fahimfaisaal Mar 29, 2022
6636af2
Merge branch 'upgrade-packageJson'
fahimfaisaal Mar 29, 2022
3905c5d
Merge branch 'upgrade-LRU'
fahimfaisaal Mar 29, 2022
42b13b8
Merge branch 'upgrade-ciphers'
fahimfaisaal Mar 29, 2022
64981b7
Merge branch 'upgrade-memoize'
fahimfaisaal Mar 29, 2022
e1c6666
Merge branch 'upgrade-abs'
fahimfaisaal Mar 29, 2022
e783547
remove: yarn lock
fahimfaisaal Mar 29, 2022
399e353
chore: fix grammer
fahimfaisaal Mar 29, 2022
189e492
Merge branch 'master' of github.com:fahimfaisaal/Javascript
fahimfaisaal Mar 29, 2022
4887aff
feat: used replace method & added test case
fahimfaisaal Mar 29, 2022
a946220
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal Mar 29, 2022
48329bf
feat: remove revert
fahimfaisaal Mar 29, 2022
08955a7
chore: added new line
fahimfaisaal Mar 29, 2022
a613aee
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal Mar 29, 2022
05ce4b8
Merge branch 'upgrade-XORCipher'
fahimfaisaal Mar 29, 2022
91f6c78
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal Mar 29, 2022
9151b89
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal Apr 15, 2022
b30f149
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal May 6, 2022
0b54cb3
Merge branch 'TheAlgorithms:master' into master
fahimfaisaal May 6, 2022
4c5c722
feat: optimized algo n to n / 2 & replaced test cases
fahimfaisaal May 6, 2022
63e4104
chore: update node version
raklaptudirm May 7, 2022
c743dbe
chore: set node version to lts
raklaptudirm May 7, 2022
36bb6a2
chore: updated the node version & added engines prop
fahimfaisaal May 7, 2022
5958e31
Merge branches 'upgrade-alphaNumericPalindrome' and 'upgrade-alphaNum…
fahimfaisaal May 7, 2022
af6133c
resolve: removed while loop
fahimfaisaal May 7, 2022
d6c9dc6
chore: added right shift ops comment
fahimfaisaal May 7, 2022
8c54c74
chore: update comment
fahimfaisaal May 7, 2022
30d8b04
chore: removed abs
fahimfaisaal May 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
node-version: "16.x"
cache: npm

- name: 📦 Install dependencies
Expand Down
29 changes: 16 additions & 13 deletions String/AlphaNumericPalindrome.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
/*****************************************************************************
* @function alphaNumericPlaindrome
* @description alphaNumericPlaindrome should return true if the string has alphanumeric characters that are palindrome irrespective of special characters and the letter case.
/**
* @function alphaNumericPalindrome
* @description alphaNumericPalindrome should return true if the string has alphanumeric characters that are palindrome irrespective of special characters and the letter case.
* @param {string} str the string to check
* @returns {Boolean}
* @see [Factorial](https://en.wikipedia.org/wiki/Palindrome)
* @returns {boolean}
* @see [Palindrome](https://en.wikipedia.org/wiki/Palindrome)
* @example
* The function alphaNumericPlaindrome() receives a string with varying formats
* The function alphaNumericPalindrome() receives a string with varying formats
* like "racecar", "RaceCar", and "race CAR"
* The string can also have special characters
* like "2A3*3a2", "2A3 3a2", and "2_A3*3#A2"
*
* But the catch is, we have to check only if the alphanumeric characters
* are palindrome i.e remove spaces, symbols, punctuations etc
* and the case of the characters doesn't matter
*
****************************************************************************/
*/
const alphaNumericPalindrome = (str) => {
if (typeof str !== 'string') {
throw new TypeError('Argument should be string')
}

const alphaNumericPlaindrome = (str) => {
// removing all the special characters and turning everything to lowercase
const newStr = str.replace(/[^a-zA-Z0-9]*/g, '').toLowerCase()
const newStr = str.replace(/[^a-z0-9]+/ig, '').toLowerCase()
const midIndex = newStr.length >> 1 // x >> y = floor(x / 2^y)

for (let i = 0; i < newStr.length; i++) {
if (newStr[i] !== newStr[newStr.length - 1 - i]) {
for (let i = 0; i < midIndex; i++) {
if (newStr.at(i) !== newStr.at(~i)) { // ~n = -(n + 1)
return false
}
}

return true
}

export { alphaNumericPlaindrome }
export default alphaNumericPalindrome
34 changes: 17 additions & 17 deletions String/test/AlphaNumericPalindrome.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { alphaNumericPlaindrome } from '../AlphaNumericPalindrome'
import alphaNumericPalindrome from '../AlphaNumericPalindrome'

test('should return true if the given string has alphanumeric characters that are palindrom irrespective of case and symbols', () => {
expect(alphaNumericPlaindrome('eye')).toBe(true)
})

test('should return true if the given string has alphanumeric characters that are palindrom irrespective of case and symbols', () => {
expect(alphaNumericPlaindrome('0_0 (: /-:) 0-0')).toBe(true)
})
describe('Testing the alpha numeric palindrome', () => {
// should return true if the given string has alphanumeric characters that are palindrome irrespective of case and symbols
it('Testing with valid alphabetic palindrome', () => {
expect(alphaNumericPalindrome('eye')).toBe(true)
expect(alphaNumericPalindrome('Madam')).toBe(true)
expect(alphaNumericPalindrome('race CAR')).toBe(true)
expect(alphaNumericPalindrome('A man, a plan, a canal. Panama')).toBe(true)
})

test('should return true if the given string has alphanumeric characters that are palindrom irrespective of case and symbols', () => {
expect(alphaNumericPlaindrome('five|_/|four')).toBe(false)
})

test('should return true if the given string has alphanumeric characters that are palindrom irrespective of case and symbols', () => {
expect(alphaNumericPlaindrome('A man, a plan, a canal. Panama')).toBe(true)
})
it('Testing with number and symbol', () => {
expect(alphaNumericPalindrome('0_0 (: /-:) 0-0')).toBe(true)
expect(alphaNumericPalindrome('03_|53411435|_30')).toBe(true)
})

test('should return true if the given string has alphanumeric characters that are palindrom irrespective of case and symbols', () => {
expect(alphaNumericPlaindrome('1 eye for of 1 eye.')).toBe(false)
it('Testing with alphabets and symbols', () => {
expect(alphaNumericPalindrome('five|_/|evif')).toBe(true)
expect(alphaNumericPalindrome('five|_/|four')).toBe(false)
})
})
17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@babel/preset-env": "^7.11.5",
"atob": "2.1.2",
"jsdom": "^16.3.0",
"node": "^14.13.1",
"node": "^16.13.2",
"node-fetch": "3.1.1"
},
"standard": {
Expand All @@ -34,5 +34,8 @@
"husky": "^7.0.4",
"jest": "^26.4.2",
"standard": "^16.0.4"
},
"engines": {
"node": ">=16.6.0"
}
}