Fix circular array.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 20 Nov 2020 00:56:19 +0000 (01:56 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 20 Nov 2020 00:56:19 +0000 (01:56 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
package-lock.json
package.json
src/utils/CircularArray.ts

index 2cb919f3f2408e757e22356c35b882c83b4a97fd..064f931c3be0b07346c07d1de71449de086c1e85 100644 (file)
       }
     },
     "typescript": {
-      "version": "4.0.5",
-      "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.5.tgz",
-      "integrity": "sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==",
+      "version": "4.1.2",
+      "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.2.tgz",
+      "integrity": "sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==",
       "dev": true
     },
     "ultron": {
index c4ade427169908565bb3583dead6798b4f31e907..67b3d25f755e2f19147689d2f8d1ee2955ab4a34 100644 (file)
@@ -71,6 +71,6 @@
     "npm-check": "^5.9.2",
     "rimraf": "^3.0.2",
     "ts-node-dev": "^1.0.0",
-    "typescript": "^4.0.5"
+    "typescript": "^4.1.2"
   }
 }
index 5dab1e2c072425a894b3a641e063aafc4c0f9198..434a8f49b57439a127a56d568ec6f570765d9073 100644 (file)
@@ -9,15 +9,15 @@ export default class CircularArray<T> extends Array<T> {
   }
 
   push(...items: T[]): number {
-    while (this.length > this.size) {
-      this.shift();
+    if (this.length + items.length > this.size) {
+      super.splice(0, (this.length + items.length) - this.size);
     }
     return super.push(...items);
   }
 
   unshift(...items: T[]): number {
-    while (this.length > this.size) {
-      this.pop();
+    if (this.length + items.length > this.size) {
+      super.splice(this.size - items.length, (this.length + items.length) - this.size);
     }
     return super.unshift(...items);
   }