In this Article we will go through how to convert 3 digits color to 6 digits color 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 toFullHexColor = color => `#${(color.startsWith('#') ? color.slice(1) : color).split('').map(c => `${c}${c}`).join('')}`;
In this Article we will go through how to convert celsius to fahrenheit 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 celsiusToFahrenheit = celsius => celsius * 9/5 + 32;
In this Article we will go through how to convert cookie to object 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 cookies = document.cookie.split(';').map(item => item.split('=')).reduce((acc, [k, v]) => (acc[k.trim().replace('"', '')] = v) && acc, {});
In this Article we will go through how to convert fahrenheit to celsius 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 fahrenheitToCelsius = fahrenheit => (fahrenheit - 32) * 5/9;
In this Article we will go through how to convert hex to rgb 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 hexToRgb = hex => hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (_, r, g, b) => `#${r}${r}${g}${g}${b}${b}`).substring(1).match(/.{2}/g).map(x => parseInt(x, 16));
In this Article we will go through how to normalize the ratio of a number in a 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 normalizeRatio = (value, min, max) => (value - min) / (max - min);
In this Article we will go through how to round a number to the nearest multiple of a given value 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 roundNearest = (value, nearest) => Math.round(value / nearest) * nearest;
In this Article we will go through how to convert degrees to radians 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 degsToRads = deg => deg * Math.PI / 180.0;
In this Article we will go through how to convert radians to degrees 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 radsToDegs = rad => rad * 180 / Math.PI;
In this Article we will go through how to calculate the distance between two points 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 distance = (p1, p2) => Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));