Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/showrin/anagram_checker

A simple program to check whether two strings are anagram or not.
https://github.com/showrin/anagram_checker

algorithm anagram-checker angram javascript testing

Last synced: about 2 hours ago
JSON representation

A simple program to check whether two strings are anagram or not.

Awesome Lists containing this project

README

        

# Anagram Checker

It's a simple program to check whether two strings are anagram or not.


## Installation

Run the following command to install this package in your package.

```
yarn add @showrin/anagram_checker
```


If you are using npm, then run the following command.

```
npm install @showrin/anagram_checker
```


## Demo

Go to the link: [https://epic-curran-723523.netlify.app/](https://epic-curran-723523.netlify.app/)


## Project Setup

Clone the repo first. To do so, go to the directory where you want to keep this repo. Then open the terminal from here and run the following command.

```
$ git clone [email protected]:Showrin/anagram_checker.git
```


Then navigate to the repository using this command.

```
$ cd anagram_checker
```


After cloning, if you are using **`yarn`**, install the required modules by running the following command.

```
$ yarn
```


Or use the following command if you are using **`npm`**.

```
$ npm install
```


Now open the **`index.html`** file with any browser and you will get the following UI. Here you can give two strings and pressing enter or pressing the button, you can check whether the given strings are anagram or not.

![Anagram Checker UI](https://i.imgur.com/ryHRyGD.png)


## Dev Dependencies

This program has following development dependencies.

| Module Name | Version | Why it's used |
| ---------------------------------------- | ------- | --------------------------------------------------- |
| @babel/plugin-transform-modules-commonjs | ^7.10.4 | It's being used for using ES6 import-export in node |
| jest | ^26.4.1 | It's being used for writing and running tests |


## Algorithm Explanation

- First convert all charaters to lowercase.
- Then remove all the space characters. (To do so, split strings by the space characters and join them. Now all the spaces have gone.)

- After that sort both strings.
- Then compare these two sorted strings.
- If they are anagram, they must be equal otherwise they are not anagram.


## Write and Run Tests

You can add your tests in **`./modules/anagram_checker.test.js`** this file like the following:

```
test("Should not be anagram", () => {
expect(anagramChecker("eat", "tar")).toBe(false);
});

test("Should not be anagram when there is an empty string", () => {
expect(anagramChecker("lamp", "")).toBe(false);
});
```


After that you can run tests using this command in the console.

```
yarn test
```


Or use the following if you are using npm.

```
npm test
```


## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

And your changes will be visible [https://epic-curran-723523.netlify.app/](https://epic-curran-723523.netlify.app/) here after getting merged into the master.


## License

[MIT](https://choosealicense.com/licenses/mit/)