Skip to content

Commit 03e3254

Browse files
committed
feat(utils): min
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 39bfe07 commit 03e3254

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/utils/__tests__/min.spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Unit Tests - min
3+
* @module commitlint-config/utils/tests/unit/min
4+
*/
5+
6+
import { Type } from '#src/enums'
7+
import testSubject from '../min'
8+
9+
describe('unit:utils/min', () => {
10+
it('should return length of shortest string in given array', () => {
11+
// Arrange
12+
const array: Type[] = [Type.BUILD, Type.DOCS, Type.REFACTOR]
13+
14+
// Act + Expect
15+
expect(testSubject(array)).to.equal(Type.DOCS.length)
16+
})
17+
})

src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*/
55

66
export { default as max } from './max'
7+
export { default as min } from './min'

src/utils/min.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @file Utilities - min
3+
* @module commitlint-config/utils/min
4+
*/
5+
6+
/**
7+
* Returns the length of the shortest string in the given `array`.
8+
*
9+
* @param {string[]} array - Array to evaluate
10+
* @return {number} Length of shortest string in `array`
11+
*/
12+
const min = (array: string[]): number => {
13+
return array.reduce((min: number, str: string, index: number): number => {
14+
return index === 0 || str.length < min ? str.length : min
15+
}, 0)
16+
}
17+
18+
export default min

0 commit comments

Comments
 (0)