File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ } )
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
export { default as max } from './max'
7
+ export { default as min } from './min'
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments