Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save derockspace/e47abc2fbc4e0c86fdadc8ee5ced3eab to your computer and use it in GitHub Desktop.

Select an option

Save derockspace/e47abc2fbc4e0c86fdadc8ee5ced3eab to your computer and use it in GitHub Desktop.
This Gist contains a collection of useful JavaScript utility functions that can be reused across different projects. It includes functions for array manipulation, string formatting, and date handling. Feel free to fork this Gist and contribute additional functions or improvements!
// Function to format a date to YYYY-MM-DD
function formatDate(date) {
const d = new Date(date);
let month = '' + (d.getMonth() + 1);
let day = '' + d.getDate();
const year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
// Function to capitalize the first letter of each word in a string
function capitalizeWords(str) {
return str.replace(/\b\w/g, function(char) { return char.toUpperCase(); });
}
// Function to find the maximum value in an array
function maxInArray(arr) {
return Math.max(...arr);
}
@derockspace

Copy link
Copy Markdown
Author

Contact: For any questions or contributions, please reach out to me on GitHub or via email at 179988301+derocktools@users.noreply.github.com.

@derockspace

Copy link
Copy Markdown
Author

Contact: For any questions or contributions, please reach out to me on GitHub or via email at 179988301+derocktools@users.noreply.github.com.

@derockspace

Copy link
Copy Markdown
Author
  1. [https://github.com/DeRock-360)]
    2.179988301+derocktools@DeRock.noreply.github.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment