In this Article we will go through how to trim some 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 trim = (str, char) => str.split(char).filter(Boolean).join();
In this Article we will go through how to uppercase the first character of each word 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 uppercaseWords = str => str.split(' ').map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join(' ');
In this Article we will go through how to capitalize 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 capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
In this Article we will go through how to check if a path is relative 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 isRelative = path => !/^([a-z]+:)?[\\/]/i.test(path);
In this Article we will go through how to check if a string consists of a repeated character sequence 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 consistsRepeatedSubstring = str => `${str}${str}`.indexOf(str, 1) !== str.length;
In this Article we will go through how to convert a string to camelcase 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 toCamelCase = str => str.trim().replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : '');
In this Article we will go through how to decapitalize 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 decapitalize = str => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
In this Article we will go through how to generate a hash of 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 hash = str => str.split('').reduce((prev, curr) => Math.imul(31, prev) + curr.charCodeAt(0) | 0, 0);
In this Article we will go through how to remove duplicate lines 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 removeDuplicateLines = str => Array.from(new Set(str.split(/\r?\n/))).join('\n');
In this Article we will go through how to remove empty lines 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 removeEmptyLines = str => str.split(/\r?\n/).filter(line => line.trim() !== '').join('\n');