In this Article we will go through how to unescape html special 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 unescape = str => str.replace(/&/g , '&').replace(/</g , '<').replace(/>/g , '>').replace(/�*39;/g , "'").replace(/"/g, '"');
In this Article we will go through how to check if a string is a palindrome 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 isPalindrome = str => str === str.split('').reverse().join('');
In this Article we will go through how to check if a url is absolute 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 isAbsoluteUrl = url => /^[a-z][a-z0-9+.-]*:/.test(url);
In this Article we will go through how to convert a string to url slug 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 slugify = string => string.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, '');
In this Article we will go through how to count the number of words in 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 countWords = str => str.trim().split(/\s+/).length;
In this Article we will go through how to count the occurrences of a character in 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 countOccurrences = (str, char) => [...str].reduce((a, v) => (v === char ? a + 1 : a), 0);
In this Article we will go through how to prepend a line number to each line of a text document 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 prependNumbers = str => str.split(/\r?\n/).map((line, i) => `${(i + 1).toString().padStart(2, ' ')} ${line}`).join('\n');
In this Article we will go through how to replace the first given number of characters of a string with another character 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 mask = (str, num, mask) => `${str}`.slice(num).padStart(`${str}`.length, mask);
In this Article we will go through how to sort lines of a text document in the alphabetical order 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 sortLines = str => str.split(/\r?\n/).sort().join('\n');
// Reverse the order
const reverseSortedLines = str => str.split(/\r?\n/).sort().reverse().join('\n');
In this Article we will go through how to sort the characters of a string in the alphabetical order 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 sort = str => str.split('').sort((a, b) => a.localeCompare(b)).join('');