Skip to content

Instantly share code, notes, and snippets.

View 4skinSkywalker's full-sized avatar
♥️
Stay strong guys!

Fred's GitHub 4skinSkywalker

♥️
Stay strong guys!
View GitHub Profile
function UnionFind(n) {
this.id = [...Array(n)].map((_, i) => i)
this.sz = [...Array(n)].map(_ => 1)
this.actual = [...this.id]
}
UnionFind.prototype._root = function (id) {
while(id != this.id[id])
id = this.id[id]
return id
function UnionFind(n) {
this.id = [...Array(n)].map((_, i) => i)
this.sz = [...Array(n)].map(_ => 1)
this.max = [...this.id]
}
UnionFind.prototype._root = function (id) {
let max = id
while(id != this.id[id]) {
id = this.id[id]
function UnionFind(n) {
this.id = [...Array(n)].map((_, i) => i)
this.sz = [...Array(n)].map(_ => 1)
this.max = 0
}
UnionFind.prototype._root = function (id) {
while (id !== this.id[id])
id = this.id[id]
return id
function mergeSort(array) {
let len = array.length
let b = 1
while (b < len) {
for (let i = 0; i + b < len; i += b * 2) {
let l = i
let r = i + b
let left = array.slice(l, l+b)
function mergeSort(array) {
let n = array.length
if (n === 1) {
return array
}
let left = array.slice(0, Math.floor(n/2))
let right = array.slice(Math.floor(n/2))
function merge(left, right) {
// REMEMBER THAT BOTH LEFT AND RIGHT ARE ALREADY ORDERED
let merged = [] // result array to return
let i = 0
let j = 0
while ( i < left.length && j < right.length ) {
import { ErrorHandler } from '@angular/core'
export class AppErrorHandler implements ErrorHandler {
handleError(error) {
alert( 'An error occured.' )
}
}
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../services/auth.service';
import { Router } from '@angular/router'
import { UnauthError } from '../common/unauth-error'
import { AppError } from '../common/app-error'
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
import { Injectable } from '@angular/core'
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
import { tap, catchError } from 'rxjs/operators'
import { throwError } from 'rxjs'
// import our custom classes
import { AppError } from '../common/app-error';
import { UnauthError } from '../common/unauth-error';
@Injectable({
import { AppError } from './app-error';
export class UnauthError extends AppError { }