Skip to content

Instantly share code, notes, and snippets.

@3200pro
3200pro / characters-in-string.js
Last active July 26, 2022 21:09
Get the number of characters in a string
const characterCount = (str, char) => str.split(char).length - 1
@3200pro
3200pro / check-object-empty.js
Created July 26, 2022 21:10
Check if the object is empty
const isEmpty = obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object
@3200pro
3200pro / wait.js
Created July 26, 2022 21:11
Wait before executing
const wait = async (time) => new Promise((resolve) => setTimeout(resolve, milliseconds));
@3200pro
3200pro / dates-difference-in-days.js
Created July 26, 2022 21:12
Get the daily difference between two dates
const daysBetween = (date1, date2) => Math.ceil(Math.abs(date1 - date2) / (1000 * 60 * 60 * 24))
@3200pro
3200pro / touch-support.js
Created July 26, 2022 21:14
Check for touch support on your device
const touchSupported = () => ('ontouchstart' in window || DocumentTouch && document instanceof DocumentTouch)
@3200pro
3200pro / insert-html-string-after.js
Created July 26, 2022 21:15
Insert HTML string after element
const insertHTMLAfter = (html, el) => el.insertAdjacentHTML('afterend', html)
@3200pro
3200pro / randomize-array.js
Created July 26, 2022 21:15
randomly arrange arrays
const shuffle = arr => arr.sort(() => Math.random() > 0.5)
@3200pro
3200pro / get-selected-text.js
Created July 26, 2022 21:16
Get selected text on web page
const getSelectedText = () => window.getSelection().toString()
@3200pro
3200pro / array-average.js
Created July 26, 2022 21:22
Calculate the average of an array
const average = (arr) => arr.reduce((a, b) => a + b) / arr.length
@3200pro
3200pro / filterThenMap.js
Created September 1, 2022 15:59
Filter Array Of Items Based On _ID Containing String & Map
items.filter(item => item._id.indexOf("string") === -1).map((item, i) => {
return(
<>
...
</>
)}