Skip to content

Instantly share code, notes, and snippets.

@lukaszgrolik
Created September 9, 2014 08:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszgrolik/e3e93f252f148343d2cf to your computer and use it in GitHub Desktop.
Save lukaszgrolik/e3e93f252f148343d2cf to your computer and use it in GitHub Desktop.
utils.js
function capitalizeFirstLetter(string)
{
return string.charAt(0).toUpperCase() + string.slice(1);
}
function moveArrayElement(arr, old_index, new_index) {
while (old_index < 0) {
old_index += arr.length;
}
while (new_index < 0) {
new_index += arr.length;
}
if (new_index >= arr.length) {
var k = new_index - arr.length;
while ((k--) + 1) {
arr.push(undefined);
}
}
arr.splice(new_index, 0, arr.splice(old_index, 1)[0]);
return arr; // for testing purposes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment