Skip to content

Instantly share code, notes, and snippets.

View Ibro's full-sized avatar

Ibrahim Šuta Ibro

View GitHub Profile
@Ibro
Ibro / typescript-intersection-types-overlap.ts
Last active March 28, 2017 06:15
TypeScript intersection types properties overlap error
interface X {
c: string;
d: string;
}
interface Y {
c: number;
e: string
}
@Ibro
Ibro / typescript-intersection-types-combining-properties.ts
Created March 29, 2017 17:21
TypeScript intersection types - combining properties
interface D { d: boolean; }
interface E { e: string; }
interface F { f: number; }
interface A { x: D; }
interface B { x: E; }
interface C { x: F; }
type ABC = A & B & C;
@Ibro
Ibro / typescript-intersection-types-interfaces.ts
Last active April 26, 2017 04:57
TypeScript intersection types - interfaces - Coding Blast - www.codingblast.com
interface D { d: boolean; }
interface E { e: string; }
interface F { f: number; }
interface A { x: D; }
interface B { x: E; }
interface C { x: F;
@Ibro
Ibro / iterators.js
Last active April 26, 2017 04:57
JavaScript Iterators - Coding Blast - www.codingblast.com
function makeIterator(array) {
let index = 0;
return {
next: function () {
if (index < array.length) {
return { value: array[index++], done: false };
} else {
return { done: true };
}
@Ibro
Ibro / iterators-array.js
Last active April 26, 2017 04:57
JavaScript Iterators - Array - Coding Blast - www.codingblast.com
let numbers = [1, 2, 3];
let it = numbers[Symbol.iterator]();
console.log(it.next()); // {value: 1, done: false}
console.log(it.next()); // {value: 2, done: false}
console.log(it.next()); // {value: 3, done: false}
console.log(it.next()); // {value: undefined, done: true}
@Ibro
Ibro / for-of-arguments.js
Last active April 26, 2017 04:57
Using for-of with arguments - Coding Blast - www.codingblast.com
function doSomething(a, b, c) {
for(let arg of arguments) {
console.log(arg);
}
}
doSomething(13, 15, 17);
@Ibro
Ibro / arguments-iterators.js
Last active April 26, 2017 04:57
Symbol.iterator with arguments object - Coding Blast - www.codingblast.com
function doSomething(a, b, c) {
let it = arguments[Symbol.iterator]();
console.log(it.next()); // {value: 13, done: false}
console.log(it.next()); // {value: 15, done: false}
console.log(it.next()); // {value: 17, done: false}
console.log(it.next()); // {value: undefined, done: true}
}
doSomething(13, 15, 17);
@Ibro
Ibro / iterators-string.js
Last active April 26, 2017 04:57
Iterators - string - Coding Blast - www.codingblast.com
let someText = 'code';
let iterator = someText[Symbol.iterator]();
console.log(iterator.next()); // { value: "c", done: false }
console.log(iterator.next()); // { value: "o", done: false }
console.log(iterator.next()); // { value: "d", done: false }
console.log(iterator.next()); // { value: "e", done: false }
console.log(iterator.next()); // { value: undefined, done: true }
@Ibro
Ibro / iterators-iterable-interfaces-typescript.ts
Last active April 26, 2017 04:57
Iterators Iterable IteratorResult - Coding Blast - www.codingblast.com
interface IteratorResult<T> {
done: boolean;
value: T;
}
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface Iterable<T> {
@Ibro
Ibro / iterators-iterable-interfaces-typescript.ts
Last active April 26, 2017 04:57
Iterators Iterable IteratorResult - Coding Blast - www.codingblast.com
interface IteratorResult<T> {
done: boolean;
value: T;
}
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
}
interface Iterable<T> {