Skip to content

Commit c7fbda5

Browse files
committed
added "palindrome" folder
1 parent a12e651 commit c7fbda5

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

palindrome/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 westtle
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

palindrome/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const prompt = require("prompt-sync")({sigint: true}); // prompt-sync (4.2.0) - https://www.npmjs.com/package/prompt-sync/v/4.2.0
2+
3+
let userString = getUserInput("Input a word or a sentence to check").trim();
4+
5+
function getUserInput(question) {
6+
do {
7+
var input = prompt(`${question}: `);
8+
} while (!input.trim().length); // While length is 0 (false), but got reversed to 1 (true) because the negation.
9+
10+
return input;
11+
};
12+
13+
function palindrome(string) {
14+
let stringFiltered = string.toLowerCase().replace(/[^A-Za-z0-9]/g, ""); // Remove all non-alphanumerics characters.
15+
let reverseStringFiltered = stringFiltered.split("").reverse().join("");
16+
17+
console.log(`\n${string} > ${stringFiltered}`);
18+
console.log(stringFiltered === reverseStringFiltered ? `"${string}" is a palindrome.` : `"${string}" is NOT a palindrome.`);
19+
};
20+
21+
palindrome(userString);
22+
23+
// Some tests.
24+
palindrome("Hello World!");
25+
palindrome("A man, a plan, a canal. Panama");
26+
palindrome("No lemons, no melon");
27+
palindrome("Never odd or even");
28+
palindrome("almostomla");

palindrome/package-lock.json

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

palindrome/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "palindrome",
3+
"description": "Check to see if a word or a sencence is a palindrome!",
4+
"author": "westtle",
5+
"version": "1.0.0",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/westtle/code-dump.git"
9+
},
10+
"keywords": [
11+
"javascript",
12+
"node",
13+
"palindrome"
14+
],
15+
"license": "MIT",
16+
"main": "index.js",
17+
"scripts": {
18+
"start": "node index.js"
19+
},
20+
"dependencies": {
21+
"prompt-sync": "^4.2.0"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/westtle/code-dump/issues"
25+
}
26+
}

0 commit comments

Comments
 (0)