In this Article we will go through how to get the yesterday 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 yesterday = (d => new Date(d.setDate(d.getDate() - 1)))(new Date);
In this Article we will go through how to check if a number is positive 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 isPositive = number => Math.sign(number) === 1;
In this Article we will go through how to check if a string contains lower case characters 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 containsLowerCase = str => str !== str.toUpperCase();
In this Article we will go through how to check if a string contains only letters 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 isAlpha = str => /^[A-Z]+$/i.test(str);
In this Article we will go through how to check if a value is a business identifier code 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 isBIC = value => /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value);
In this Article we will go through how to check if a value is a string 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 isString = value => Object.prototype.toString.call(value) === '[object String]';
In this Article we will go through how to add am pm suffix to an hour 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 suffixAmPm = h => `${h % 12 === 0 ? 12 : h % 12}${h < 12 ? 'am' : 'pm'}`;
In this Article we will go through how to calculate the number of difference days between two dates 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 diffDays = (date, otherDate) => Math.ceil(Math.abs(date - otherDate) / (1000 * 60 * 60 * 24));
In this Article we will go through how to convert a date to yyyy-mm-dd format 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 formatYmd = date => date.toISOString().slice(0, 10);
In this Article we will go through how to format a date for the given locale 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 format = (date, locale) => new Intl.DateTimeFormat(locale).format(date);