-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* serious role position stuff * kill meh * Update Role.js * Update Guild.js * Update Role.js
- Loading branch information
Showing
4 changed files
with
39 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Moves an element in an array *in place* | ||
* @param {Array} array Array to modify | ||
* @param {*} element Element to move | ||
* @param {number} newIndex Index or offset to move the element to | ||
* @param {boolean} [offset=false] Move the element by an offset amount rather than to a set index | ||
* @returns {Array} | ||
*/ | ||
module.exports = function moveElementInArray(array, element, newIndex, offset = false) { | ||
const index = array.indexOf(element); | ||
newIndex = (offset ? index : 0) + newIndex; | ||
if (newIndex > -1 && newIndex < array.length) { | ||
const removedElement = array.splice(index, 1)[0]; | ||
array.splice(newIndex, 0, removedElement); | ||
} | ||
return array; | ||
}; |