Skip to content

Instantly share code, notes, and snippets.

setTimeout(() => {
console.log('Hello timeout!');
}, 1000); //will print "Hello timeout!" once, after 1 second
setInterval(() => {
console.log('Hello interval!');
}, 1000) //will print "Hello interval!" every 1 second
console.log('Start');
setTimeout(() => {
console.log('Hello timeout!');
}, 0);
console.log('End');
setTimeout(function run() {
console.log('Hello!');
setTimeout(run, 1000);
}, 1000);
function insertionSort(array) {
let i = 1;
let x;
while (i < array.length) {
x = array[i]
let j = i - 1;
while (j >= 0 && array[j] > x) {
array[j + 1] = array[j];
j = j - 1;
}
function merge(left, right) {
const result = [];
while (left.length > 0 && right.length > 0) {
if (left[0] <= right[0]) {
result.push(left[0]);
left = left.slice(1);
} else {
result.push(right[0]);
right = right.slice(1);
function quickSort(array, low, high) {
if (low < high) {
const p = partition(array, low, high);
quickSort(array, low, p);
quickSort(array, p + 1, high);
}
}
function partition(array, low, high) {
const middleIndex = Math.floor((high + low) / 2);
function bubbleSort(array) {
let swapped = true;
while (swapped) {
swapped = false;
for (let i = 1; i < array.length; i += 1) {
if (array[i - 1] > array[i]) {
swapped = true;
const temp = array[i];
array[i] = array[i - 1];
@Dornhoth
Dornhoth / Dog.ts
Last active December 20, 2019 12:56
export default interface Dog {
name: string;
age: number;
favoritePark: string;
profilePicture?: string;
}
import { Injectable } from '@angular/core';
import Dog from '../models/Dog';
@Injectable({
providedIn: 'root'
})
export class MembersService {
get members(): Dog[] {
return [
{
<h2>List of Members:</h2>
<app-dog-item *ngFor="let member of members" [member]="member"></app-dog-item>