Skip to content

Instantly share code, notes, and snippets.

@romdim
Created May 12, 2020 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romdim/52335a2bff9719d6eb7be861d6b03c57 to your computer and use it in GitHub Desktop.
Save romdim/52335a2bff9719d6eb7be861d6b03c57 to your computer and use it in GitHub Desktop.
Javascript helper functions
const isLowerCase = str => str === str.toLowerCase();
const isNullOrUndefined = val => val === undefined || val === null;
const smoothScroll = element =>
document.querySelector(element).scrollIntoView({
behavior: 'smooth'
});
const splitLines = str => str.split(/\r?\n/);
// Arrays:
const matchingElements = (array1, array2) =>
array1.filter(element => array2.includes(element));
const arrayDiff = (array1, array2) => {
const setArray = new Set(array2);
return array1.filter(arr => !setArray.has(arr));
};
const removeDuplicates = arr => [...new Set(arr)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment