In this Article we will go through how to create cartesian product 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 cartesian = (...sets) => sets.reduce((acc, set) => acc.flatMap((x) => set.map((y) => [...x, y])), [[]]);
In this Article we will go through how to empty 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 empty = arr => arr.length = 0;
In this Article we will go through how to get indices 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 indices = (arr, value) => arr.reduce((acc, v, i) => (v === value ? [...acc, i] : acc), []);
In this Article we will go through how to get the average of 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 average = arr => arr.reduce((a, b) => a + b, 0) / arr.length;
In this Article we will go through how to check if a date is today 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 isToday = (date) => date.toISOString().slice(0, 10) === new Date().toISOString().slice(0, 10);
In this Article we will go through how to check if a flat array has duplicate values 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 hasDuplicateValues = arr => new Set(arr).size !== arr.length;
In this Article we will go through how to check if a number is even 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 isEven = number => number % 2 === 0;
In this Article we will go through how to check if a number is in a given range 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 inRange = (num, a, b, threshold = 0) => (Math.min(a, b) - threshold <= num && num <= Math.max(a, b) + threshold);
In this Article we will go through how to check if a number is odd 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 isOdd = number => number % 2 !== 0;
In this Article we will go through how to check if a string contains only letters and 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 isAlphanumeric = str => /^[0-9A-Z]+$/i.test(str);