Skip to content

Instantly share code, notes, and snippets.

@dhbalaji
Last active December 1, 2020 10:20
Show Gist options
  • Save dhbalaji/9bd39f27c81a6d05c57c1d067d7963a5 to your computer and use it in GitHub Desktop.
Save dhbalaji/9bd39f27c81a6d05c57c1d067d7963a5 to your computer and use it in GitHub Desktop.

Capitalize first line

  function capitalizeFirstLetter(str) {
    return `${a.charAt(0).toUpperCase()}${a.slice(1)}`;
  }

Get selected text from DOM

  function getSelectedText() {
    return window.getSelection().toString();
  }

Sort array of numbers

  const arr = [10,9,1,11];
  function sortNumbers = (a , b) => a - b;
  arr.sort(sortNumbers);

clone array, objects

  const arr = [1,2,3];
  const arrCopy = [...arr];
  
  const obj = {a:1};
  const objCopy = {...obj};

merging objects without side effects

  Object.assign({}, obj1, obj2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment