This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injectable} from '@angular/core'; | |
import {Http, Headers, Response, Request, BaseRequestOptions, RequestMethod, ResponseContentType} from '@angular/http'; | |
import {Observable} from 'rxjs/Rx'; | |
@Injectable() | |
export class HttpClient { | |
constructor(private http: Http) {} | |
post(url: string, body: any = {}) { | |
return this.request(url, RequestMethod.Post, body); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component, OnInit} from '@angular/core'; | |
import {HttpClient} from './http.service'; | |
import {user} from './user'; | |
import {Response, Request} from '@angular/http'; | |
@Component({selector: 'my-app', templateUrl: './app.component.html'}) | |
export class AppComponent implements OnInit { | |
constructor(private Http : HttpClient) { | |
this.URL ='http://localhost:3000/api'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<app-header (filterChange)="filterValueChange($event);"></app-header> | |
<ng-loader [loaded]="loaded"></ng-loader> | |
<main-result [Users]="Users"></main-result> | |
<app-footer></app-footer> | |
@Component({ | |
selector: 'main-result', | |
templateUrl: './main-result.html' | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function diffFromArray(array1,array2){ | |
var map = {}; | |
var out = []; | |
if(array1.length == 0 || array2.length === 0 ){ | |
return null | |
}; | |
array1.forEach(function(element){ | |
map[element] = 1; | |
}); | |
array2.forEach(function(element){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Removing duplicates of an array and returning an array of only unique elements | |
// ES6 Implementation | |
var array = [1, 2, 3, 5, 1, 5, 9, 1, 2, 8]; | |
Array.from(new Set(array)); // [1, 2, 3, 5, 9, 8] | |
// done with set in ES6 as it will not allow duplicates in array | |
// ES5 Implementation | |
var array = [1, 2, 3, 5, 1, 5, 9, 1, 2, 8]; | |
uniqueArray(array); // [1, 2, 3, 5, 9, 8] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function assignDeep(target, ...sources) { | |
for (let source of sources) { | |
for (let key in source) { | |
if (isObject(source[key])) { | |
if (!isObject(target[key])) { | |
target[key] = {} | |
} | |
assignDeep(target[key], source[key]) | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isEquivalent(a, b) { | |
// Create arrays of property names | |
var aProps = Object.getOwnPropertyNames(a); | |
var bProps = Object.getOwnPropertyNames(b); | |
// If number of properties is different, | |
// objects are not equivalent | |
if (aProps.length != bProps.length) { | |
return false; | |
} | |
for (var i = 0; i < aProps.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debouce(fn, delay){ | |
var timer = null | |
return function(){ | |
let content = this; | |
var args = arguments; | |
clearTimeout(timer); | |
timer = setTimeout(()=>{ | |
fn.apply(this,arguments) | |
},delay) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function() { | |
let app = document.getElementById('todo-app'); | |
// attach event listener to whole container | |
app.addEventListener('click', function(e) { | |
if (e.target && e.target.nodeName === 'LI') { | |
let item = e.target; | |
alert('you clicked on item: ' + item.innerHTML); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function intersection(firstArray, secondArray) { | |
// array1 = [1,5,6,7,8]; | |
// array2 = [3,4,5,7,9]; | |
var hashmap = {}; | |
var intersectionArray = []; | |
// assign 1 to all index in hashmap | |
firstArray.forEach(function(element) { | |
hashmap[element] = 1; | |
}); |