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
class Observer { | |
constructor (fn) { | |
this.update = fn; | |
} | |
} | |
class Subject { | |
constructor() { | |
this.observers = []; | |
} | |
addObserver(observer) { |
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
class User { | |
constructor(name, auth) { | |
this.name = name | |
this.auth = auth | |
} | |
} | |
class UserFactory { | |
static createUser(name, auth) { | |
if(auth === 'admin') new User(name, 1) |
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
class SingletonLogin { | |
constructor(name,password){ | |
this.name = name; | |
this.password = password; | |
} | |
static getInstance(name,password){ | |
if(!this.instance)this.instance = new SingletonLogin(name,password); | |
return this.instance; | |
} | |
} |
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
const heapSort = array => { | |
for (let i = Math.floor(array.length / 2 - 1); i >= 0; i--) { | |
heapify(array, i, array.length); | |
} | |
for (let i = Math.floor(array.length - 1); i > 0; i--) { | |
swap(array, 0, i); | |
heapify(array, 0, i); | |
} | |
return array; | |
}; |
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 mergeSort(arr) { | |
if(arr.length <= 1) return arr; | |
const midIndex = arr.length/2 | 0; | |
const leftArr = arr.slice(0, midIndex); | |
const rightArr = arr.slice(midIndex, arr.length); | |
return merge(mergeSort(leftArr), mergeSort(rightArr)); | |
} | |
function merge(leftArr, rightArr) { | |
const result = []; |
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 quickSort(arr, left, right) { | |
if (left < right) { | |
let pos = left - 1; | |
for(let i = left; i <= right; i++) { | |
let pivot = arr[right]; | |
pos++; | |
let temp = arr[pos]; | |
arr[pos] = arr[i]; | |
arr[i] = temp; | |
} |
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 quickSort(arr) { | |
if(arr.length <= 1) return arr; | |
const pivot = arr.length / 2 | 0; | |
const pivotValue = arr.splice(pivot, 1)[0]; | |
const leftArr = []; | |
const rightArr = []; | |
arr.forEach(val => { | |
val > pivotValue ? rightArr.push(val) : leftArr.push(val); | |
}) | |
return [ ...quickSort(leftArr), pivotValue, ...quickSort(rightArr)]; |
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 bubbleSort(arr){ | |
for(let i = 0; i < arr.length; i++) { | |
let flag = true | |
for(let j = 0; j < arr.length - i - 1; j++) { | |
if(arr[j] > arr[j+1]) { | |
flag = false | |
let temp = arr[j] | |
arr[j] = arr[j+1] | |
arr[j+1] = temp | |
} |
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 bubbleSort(arr){ | |
for(let i = 0; i < arr.length; i++) { | |
for(let j = 0; j < arr.length - i - 1; j++) { | |
if(arr[j] > arr[j+1]) { | |
let temp = arr[j] | |
arr[j] = arr[j+1] | |
arr[j+1] = temp | |
} | |
} | |
} |
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
public class StudentTest { | |
@Test | |
public void test(){ | |
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); | |
Student student = (Student) context.getBean("student"); | |
System.out.println(student.getName()); | |
} | |
} |