Skip to content

Instantly share code, notes, and snippets.

View camelcaseblog's full-sized avatar

camelcaseblog

View GitHub Profile
var e = new Error();
e.name = ‘MyError’;
throw e;
// is equivalent to:
class MyError extends Error {}
throw MyError();
>>> (7).toString().padStart(3, '0');
"007"
>>> f'{7:03}'
'007'
>>> const sort = require('immutable-sort')
>>> var a = [3, 2, 1];
>>> var b = sort(a);
>>> b
[1, 2, 3]
>>> a
[3, 2, 1]
>>> var a = [3, 2, 1];
>>> var b = a.sort();
>>> b
[1, 2, 3]
>>> a
[1, 2, 3]
>>> a = [3, 2, 1]
>>> sorted(a)
[1, 2, 3]
>>> a
[3, 2, 1]
>>> a.sort()
>>> a
[1, 2, 3]
x = {'a': 1, 'b': 2}
y = {'b': 2, 'a': 1}
_.isEqual(x, y) // true
x = {'a': 1, 'b': 2}
y = {'b': 2, 'a': 1}
x === y // false
x == y // false
HashMap<String, Object> map1 = new HashMap<String, Object>();
map1.put("a", 1);
map1.put("b", 2);
TreeMap<String, Object> map2 = new TreeMap<String, Object>();
map2.put("b", 2)
map2.put("a", 1);
map1.equals(map2); // true
>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 2, 'a': 1}
>>> x == y
True