Skip to content

Instantly share code, notes, and snippets.

Avatar

camelcaseblog

View GitHub Profile
View error_name_vs_inheritance.js
var e = new Error();
e.name = ‘MyError’;
throw e;
// is equivalent to:
class MyError extends Error {}
throw MyError();
View 07_javascript_array_sort_immutable
>>> const sort = require('immutable-sort')
>>> var a = [3, 2, 1];
>>> var b = sort(a);
>>> b
[1, 2, 3]
>>> a
[3, 2, 1]
View 07_javascript_array_sort
>>> var a = [3, 2, 1];
>>> var b = a.sort();
>>> b
[1, 2, 3]
>>> a
[1, 2, 3]
View 07_python_list_sort
>>> a = [3, 2, 1]
>>> sorted(a)
[1, 2, 3]
>>> a
[3, 2, 1]
>>> a.sort()
>>> a
[1, 2, 3]
View 07_javascript_object_comparison
x = {'a': 1, 'b': 2}
y = {'b': 2, 'a': 1}
x === y // false
x == y // false
View 07_java_hashmap_comparison
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
View 07_python_dict_comparison
>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 2, 'a': 1}
>>> x == y
True