In this Article we will go through how to find the length of the longest string 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 findLongest = words => Math.max(...(words.map(el => el.length)));
In this Article we will go through how to find the maximum item of an array by given key 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 maxBy = (arr, key) => arr.reduce((a, b) => a[key] >= b[key] ? a : b, {});
In this Article we will go through how to find the maximum item 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 max = arr => Math.max(...arr);
In this Article we will go through how to find the minimum item of an array by given key 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 minBy = (arr, key) => arr.reduce((a, b) => a[key] < b[key] ? a : b, {});
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 check if an array is empty 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 isEmpty = arr => !Array.isArray(arr) || arr.length === 0;