Skip to content

Commit 45bd0a9

Browse files
author
Max Wan
committed
move index in array tome
1 parent 1a60c54 commit 45bd0a9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,22 @@ ArrayTome.prototype.rename = function () {
14511451
return this;
14521452
};
14531453

1454+
ArrayTome.prototype.move = function (key, newKey) {
1455+
var changes = {};
1456+
changes[key] = newKey;
1457+
1458+
if (newKey > key) {
1459+
for (let i = key; i < newKey; i++) {
1460+
changes[i + 1] = i.toString();
1461+
}
1462+
} else if (newKey < key) {
1463+
for (let i = newKey; i < key; i++) {
1464+
changes[i] = (i + 1).toString();
1465+
}
1466+
}
1467+
1468+
return this.rename(changes);
1469+
};
14541470

14551471
ArrayTome.prototype.sort = function () {
14561472
this._arr.sort.apply(this._arr, arguments);

0 commit comments

Comments
 (0)