Skip to content

Instantly share code, notes, and snippets.

View hanmd82's full-sized avatar

Mingding Han hanmd82

View GitHub Profile
@hanmd82
hanmd82 / es6-arrays.js
Last active January 29, 2018 17:25
ES6 katas for Arrays - http://es6katas.org/
// 29: array - `Array.from` static method
describe('`Array.from` converts an array-like object or list into an Array', () => {
const arrayLike = {0: 'one', 1: 'two', length: 2};
it('call `Array.from` with an array-like object', function() {
const arr = Array.from(arrayLike);
assert.deepEqual(arr, ['one', 'two']);
@hanmd82
hanmd82 / es6-strings.js
Last active January 3, 2018 15:17
ES6 katas for Strings - http://es6katas.org/
// 63: String - `includes()`
describe('`string.includes()` finds string within another string', function() {
describe('find a single character', function() {
it('in a three char string', function() {
const searchString = 'x';
assert.equal('xyz'.includes(searchString), true);
});
it('reports false if character was not found', function() {
@hanmd82
hanmd82 / es6-symbols.js
Last active January 3, 2018 14:04
ES6 katas for Symbols - http://es6katas.org/
// 34: symbol
// A symbol is a unique and immutable data type and may be used as an identifier for object properties
// read more at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
describe('Symbol', function() {
it('`Symbol` lives in the global scope', function(){
const expected = Symbol;
assert.equal(Symbol, expected);
});
@hanmd82
hanmd82 / es6-sets.js
Last active January 3, 2018 13:55
ES6 katas for Sets - http://es6katas.org/
// 47: Set - basics
describe('`Set` lets you store unique values of any type', function(){
it('`Set` is a new global constructor function', function() {
assert.equal(typeof Set, 'function');
});
it('every value in a set is unique', function() {
let set = new Set();
@hanmd82
hanmd82 / es6-maps.js
Last active January 3, 2018 13:30
ES6 katas for Maps - http://es6katas.org/
// 44: Map - basics
describe('`Map` is a key/value map', function(){
it('`Map` is a new global constructor function', function() {
assert.equal(typeof Map, 'function');
});
it('provides `new Map().set()` to add key+value pair, `get()` to read it by key', function() {
let map = new Map();
@hanmd82
hanmd82 / es6-unicode.js
Created January 3, 2018 06:12
ES6 katas for Unicode - http://es6katas.org/
// 17: unicode - in strings
describe('unicode strings', () => {
it('are \\u prefixed', () => {
const nuclear = `\u2622`;
assert.equal(nuclear, '☢');
});
it('value is 4 bytes/digits', () => {
@hanmd82
hanmd82 / es6-numbers.js
Created January 3, 2018 06:09
ES6 katas for Numbers - http://es6katas.org/
// 55: Number - isInteger
describe('`Number.isInteger()` determines if a value is an integer', function(){
const isTrue = (what) => assert.equal(what, true);
const isFalse = (what) => assert.equal(what, false);
it('`isInteger` is a static function on `Number`', function() {
const whatType = 'function';
assert.equal(typeof Number.isInteger, whatType);
@hanmd82
hanmd82 / es6-objects.js
Created January 3, 2018 06:04
ES6 katas for Objects - http://es6katas.org/
// 54: Object - is
describe('`Object.is()` determines whether two values are the same', function(){
describe('scalar values', function() {
it('1 is the same as 1', function() {
const areSame = Object.is(1, 1);
assert.equal(areSame, true);
});
it('int 1 is different to string "1"', function() {
@hanmd82
hanmd82 / es6-iterators.js
Last active January 3, 2018 03:03
ES6 katas for Iterators - http://es6katas.org/
// The iterator protocol defines a standard way to produce a sequence of values (either finite or infinite).
// read more at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
// 37: iterator/iterable - array.
describe('array is a built-in iterable object', function() {
const arr = ['a', 'B', 'see'];
describe('the iterator', function() {
@hanmd82
hanmd82 / es6-classes.js
Last active January 2, 2018 14:48
ES6 katas for Classes - http://es6katas.org/
// 22: class - creation
describe('class creation', () => {
it('is as simple as `class XXX {}`', function() {
class TestClass {};
const instance = new TestClass();
assert.equal(typeof instance, 'object');
});