In this Article we will go through how to initialize the current date but set time to midnight only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const midnightOfToday = () => new Date(new Date().setHours(0, 0, 0, 0));
In this Article we will go through how to cast a value as an array only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const castArray = value => Array.isArray(value) ? value : [value];
In this Article we will go through how to compare two arrays regardless of order only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const isEqual = (a, b) => JSON.stringify(a.sort()) === JSON.stringify(b.sort());
In this Article we will go through how to clone an array only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const clone = arr => arr.slice(0);
In this Article we will go through how to compare two arrays only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
In this Article we will go through how to convert an array of strings to numbers only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const toNumbers = arr => arr.map(Number);
In this Article we will go through how to count the occurrences of array elements only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const countOccurrences = arr => arr.reduce((prev, curr) => (prev[curr] = ++prev[curr] || 1, prev), {});
In this Article we will go through how to get the tomorrow date only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const tomorrow = (d => new Date(d.setDate(d.getDate() + 1)))(new Date);
In this Article we will go through how to create an array of cumulative sum only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const accumulate = arr => arr.map((sum => value => sum += value)(0));
In this Article we will go through how to count the occurrences of a value in an array only using single line of code in JavaScript. This is a one-line JavaScript code snippet that uses one of the most popular ES6 features => Arrow Function.
Let's define this short function:
const countOccurrences = (arr, val) => arr.reduce((a, v) => (v === val ? a + 1 : a), 0);