From 3011c25279a1884390c8149910d79ecdc5661923 Mon Sep 17 00:00:00 2001 From: Grzegorz Kucmierz Date: Sun, 22 Dec 2019 21:16:33 +0100 Subject: [PATCH] Insert value into an array --- insert-value-into-an-array/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 insert-value-into-an-array/index.js diff --git a/insert-value-into-an-array/index.js b/insert-value-into-an-array/index.js new file mode 100644 index 0000000..c408977 --- /dev/null +++ b/insert-value-into-an-array/index.js @@ -0,0 +1,9 @@ +// https://www.codewars.com/kata/insert-value-into-an-array/javascript + +Object.defineProperty(Array.prototype, 'insert', { + enumerable: false, + value: function(idx, val) { + this.splice(idx, 0, val); + return this; + } +});