const isArray = Array.isArray(arr);
const isArray = arr instanceof Array;
const sum = (arr) => arr.reduce((a, b) => a + b);
const average = (arr) => arr.reduce((a, b) => a + b) / arr.length;
const sort = (arr) => arr.slice().sort((a, b) => a - b);
const clone = (arr) => arr.slice();
const clone = (arr) => [...arr];
const findUniqueValues = (arr) => arr.filter((i) => arr.indexOf(i) === arr.lastIndexOf(i));
const lastElement = (arr) => arr[arr.length-1];
const lastElement = (arr) => arr.slice(-1)[0];
const lastElement = (arr) => arr.slice().pop();
const shuffle = (arr) => arr.slice().sort(() => Math.random() - 0.5);
const removeDuplicates = (arr) => [...new Set(arr)];
const merge = (arr1, arr2) => [].concat(arr1, arr2);
const merge = (arr1, arr2) => [...arr1, ...arr2];
const merge = (arr1, arr2) => [...new Set(arr1.concat(arr2))];
const merge = (arr1, arr2) => [...new Set([...arr1, ...arr2])];
const removeFalsyValues = (arr) => arr.filter(x => x);
const removeFalsyValues = (arr) => arr.filter(Boolean);
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
const reverseString = (str) => str.split("").reverse().join("");
const reverseString = (str) => [...str].reverse().join();
const toNumber = (str) => Number(str);
const toNumber = (str) => +str;
const toCharArray = (str) => str.split('');
const toCharArray = (str) => [...str];
const toCharArray = (str) => Array.from(str);
const toCharArray = (str) => Object.assign([], str);
const snakeToCamel = (str) => str.toLowerCase().replace(/(_\w)/g, (word) => word.toUpperCase().substr(1));
const daysBetweenDates = (date1, date2) => Math.ceil(Math.abs(date1 - date2) / (1000 * 60 * 60 * 24));
const getWeekday = (date) => ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][date.getDay()];
const getWeekday = (date) => date.toLocaleString('en-US', {weekday: 'long'});
const randomNumber = (rangeStart, rangeEnd) => new Date().getTime() % rangeEnd + rangeStart;
const randomNumber = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
const randomHexColor = () => `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
const randomBoolean = () => Math.random() >= 0.5;
const isEmpty = (arr) => !Array.isArray(arr) || !arr.length;
const includes = (arr, value) => arr.indexOf(value) != -1;
const includes = (arr, value) => arr.includes(value);
const isWeekend = (date) => [5, 6].indexOf(date.getDay()) !== -1;
const checkPhoneNumber = (phone) => (/^(\+91|0)?\s?\d{10}$/).test(phone);
const isCamelCase = (str) => (/^[a-z][a-zA-Z0-9]$/).test(str);
const getSelectedText = () => window.getSelection().toString();
const toggle = (flag) => !flag;
const swap = (a,b) => [a,b] = [b,a];
- https://dev.to/ovi/20-javascript-one-liners-that-will-help-you-code-like-a-pro-4ddc
- https://dev.to/saviomartin/20-killer-javascript-one-liners-94f
- https://dev.to/ruppysuppy/7-killer-one-liners-in-javascript-one
- https://dev.to/everlyhealth/our-favorite-javascript-one-liners-3l7n
- https://medium.com/dailyjs/10-javascript-oneliners-you-have-got-to-add-your-arsenal-as-a-developer-b733cbb973b2
- https://www.makeuseof.com/javascript-one-liners-you-should-know/
- https://www.samanthaming.com/tidbits/?filter=JS#CodeTidbits