forked from mrclapham/blockything
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Works on the first click if not touching any edge
- Loading branch information
Showing
3 changed files
with
35 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// http://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another | ||
Array.prototype.move = function(pos1, pos2) { | ||
// local variables | ||
var i, tmp; | ||
// cast input parameters to integers | ||
pos1 = parseInt(pos1, 10); | ||
pos2 = parseInt(pos2, 10); | ||
// if positions are different and inside array | ||
if (pos1 !== pos2 && 0 <= pos1 && pos1 <= this.length && 0 <= pos2 && pos2 <= this.length) { | ||
// save element from position 1 | ||
tmp = this[pos1]; | ||
// move element down and shift other elements up | ||
if (pos1 < pos2) { | ||
for (i = pos1; i < pos2; i++) { | ||
this[i] = this[i + 1]; | ||
} | ||
} | ||
// move element up and shift other elements down | ||
else { | ||
for (i = pos1; i > pos2; i--) { | ||
this[i] = this[i - 1]; | ||
} | ||
} | ||
// put element from position 1 to destination | ||
this[pos2] = tmp; | ||
} | ||
} |
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