Quellcode durchsuchen

Istanbul code coverage

sanex3339 vor 9 Jahren
Ursprung
Commit
bfed52ef27
3 geänderte Dateien mit 9 neuen und 4 gelöschten Zeilen
  1. 2 2
      dist/index.js
  2. 2 2
      src/Utils.ts
  3. 5 0
      test/Utils.spec.ts

+ 2 - 2
dist/index.js

@@ -111,8 +111,8 @@ module.exports =
 	        value: function arrayRotate(array, times) {
 	            var reverse = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
 	
-	            if (times < 0) {
-	                return;
+	            if (times <= 0) {
+	                return array;
 	            }
 	            var newArray = array,
 	                temp = void 0;

+ 2 - 2
src/Utils.ts

@@ -29,8 +29,8 @@ export class Utils {
      * @returns {T[]}
      */
     public static arrayRotate <T> (array: T[], times: number, reverse: boolean = false): T[] {
-        if (times < 0) {
-            return;
+        if (times <= 0) {
+            return array;
         }
 
         let newArray: T[] = array,

+ 5 - 0
test/Utils.spec.ts

@@ -27,6 +27,11 @@ describe('Utils', () => {
         it('should rotate (shift) array by a given value in reverse directions', () => {
             assert.deepEqual(Utils.arrayRotate(array, 2, true), [3, 4, 5, 6, 1, 2]);
         });
+
+        it('should do nothing if value <= 0', () => {
+            assert.deepEqual(Utils.arrayRotate(array, 0, true), [1, 2, 3, 4, 5, 6]);
+            assert.deepEqual(Utils.arrayRotate(array, -1, true), [1, 2, 3, 4, 5, 6]);
+        });
     });
 
     describe('btoa (string: string): string', () => {