In this Article we will go through how to check if a year is leap year 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 isLeapYear = year => (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
In this Article we will go through how to check if all array elements are equal to 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 isEqual = (arr, value) => arr.every(item => item === value);
In this Article we will go through how to check if all items in an array are equal 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 areEqual = arr => arr.length > 0 && arr.every(item => item === arr[0]);
In this Article we will go through how to check if an array contains a value matching some criterias 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 contains = (arr, criteria) => arr.some(v => criteria(v));
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 check if a value is an 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 isObject = v => (v !== null && typeof v === 'object');
In this Article we will go through how to check if a string is lower case 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 isLowerCase = str => str === str.toLowerCase();
In this Article we will go through how to check if a string is upper case 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 isUpperCase = str => str === str.toUpperCase();
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 number 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 isNumber = value => !isNaN(parseFloat(value)) && isFinite(value);