Skip to content

Instantly share code, notes, and snippets.

View NiallJoeMaher's full-sized avatar
🎯
Focusing

Niall Maher NiallJoeMaher

🎯
Focusing
View GitHub Profile
// trimStart
'Hello World'.trimEnd();
// returns 'Hello World'
' Hello World'.trimEnd();
// returns ' Hello World'
' Hello World '.trimEnd();
// returns ' Hello World'
// trimLeft
'Hello World'.trimRight();
// trimStart
'Hello World'.trimStart();
// returns 'Hello World'
' Hello World'.trimStart();
// returns 'Hello World'
' Hello World '.trimStart();
//returns 'Hello World '
// trimLeft
'Hello World'.trimLeft();
//With Object.fromEntries, you can convert from Map to Object:
const testMap = new Map([ ['hello', 'world'], ['lorem', 42] ]);
const result1 = Object.fromEntries(testMap);
console.log(result1); // { hello: "world", lorem: 42 }
//With Object.fromEntries, you can convert from Array to Object:
const testArray = [ ['first', 0], ['second', 1], ['third', 2] ];
const result2 = Object.fromEntries(testArray);
console.log(result2); // { first: 0, second: 1, third: 2 }
// Before
try {
...
} catch(error) {
...
}
// After
try {
...
} catch {
const testArray1 = ["It's Always Sunny in", "", "Philadelphia"];
// First using a map for comparison
testArray1.map(x => x.split(" "));
//returns [["It's", "Always", "Sunny","in"],[""],["Philadelphia"]]
// Now let us see flatMap in action!
testArray1.flatMap(x => x.split(" "));
//returns ["It's","Sunny","in", "", "Philadelphia"]
// The simple one :P
const testArray1 = [1, 2, [3, 4]];
testArray1.flat(); // returns [1, 2, 3, 4]
const testArray2 = [1, 2, [3, 4, [5, 6]]];
testArray2.flat();
// returns [1, 2, 3, 4, [5, 6]];
testArray2.flat(2); // goes two levels deep recursively as we passed the parameter
// returns [1, 2, 3, 4, 5, 6];
@NiallJoeMaher
NiallJoeMaher / 3D Buttons, CSS only!.markdown
Created September 5, 2015 13:41
3D Buttons, CSS only!