https://github.com/writetome51/get-first-last-alphabetical
2 functions that both receive an array of strings: one returns the first string in the sorted array, the other returns the last
https://github.com/writetome51/get-first-last-alphabetical
alphabetical alphabetize first javascript last typescript
Last synced: 3 months ago
JSON representation
2 functions that both receive an array of strings: one returns the first string in the sorted array, the other returns the last
- Host: GitHub
- URL: https://github.com/writetome51/get-first-last-alphabetical
- Owner: writetome51
- License: other
- Created: 2019-03-06T21:57:06.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-26T22:25:40.000Z (about 6 years ago)
- Last Synced: 2025-02-02T10:48:43.070Z (4 months ago)
- Topics: alphabetical, alphabetize, first, javascript, last, typescript
- Language: TypeScript
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# getFirstAlphabetical(items): any
Creates a copy of `items` re-arranged in alphabetical order and returns the
first item in sorted result.
Does not modify `items`.# getLastAlphabetical(items): any
Creates a copy of `items` re-arranged in alphabetical order and returns the
last item in sorted result.
Does not modify `items`.For both functions: if not every item in `items` is type 'string',
the function will attempt to coerce the item into a string before
doing the comparisons. None of the items are modified.Since `items` can technically include any data type, it's possible
any data type could end up being the first or last item in the
sorted result.## Examples
```
let items = ['c', 'a', 'e', '', 'g', 'j', 'z', 'o', 'r', 'x', '!'];getFirstAlphabetical(items);
// --> ''
getLastAlphabetical(items);
// --> 'z'
items = ['aa', 'a', 'A', 'AA'];getFirstAlphabetical(items);
// --> 'A'
getLastAlphabetical(items);
// --> 'aa'items = ['John Adams', 'Ben Franklin', 'William Shakespeare', 'JJ Abrams',
'Bob Newhart', 'Walter Cronkite'];getFirstAlphabetical(items);
// --> 'Ben Franklin'getLastAlphabetical(items);
// --> 'William Shakespeare'items = ['today', null, false, true];
getFirstAlphabetical(items);
// --> false
getLastAlphabetical(items);
// --> true
items = [0, false, [], {}, ''];getFirstAlphabetical(items);
// --> []
getLastAlphabetical(items);
// --> false
```## Installation
`npm i @writetome51/get-first-last-alphabetical`## Loading
```
// if using TypeScript:
import {getFirstAlphabetical, getLastAlphabetical}
from '@writetome51/get-first-last-alphabetical';
// if using ES5 JavaScript:
var firstLastAlphabetical = require('@writetome51/get-first-last-alphabetical');
var getFirstAlphabetical = firstLastAlphabetical.getFirstAlphabetical;
var getLastAlphabetical = firstLastAlphabetical.getLastAlphabetical;
```## License
[MIT](https://choosealicense.com/licenses/mit/)