Created
May 12, 2020 17:36
-
-
Save romdim/52335a2bff9719d6eb7be861d6b03c57 to your computer and use it in GitHub Desktop.
Javascript helper functions
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
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