Skip to content

Instantly share code, notes, and snippets.

@zzzgit
Created September 22, 2019 10:09
Show Gist options
  • Save zzzgit/c69cd6e98e2c16eb0bb49a2c4157bb21 to your computer and use it in GitHub Desktop.
Save zzzgit/c69cd6e98e2c16eb0bb49a2c4157bb21 to your computer and use it in GitHub Desktop.
a lib for poker
class Collection {
constructor(set) {
if (!['Set', 'Array'].includes(set.constructor.name)) {
throw new Error("Conllection 的构造函数只接收Set和Array对象")
}
this._entries = Array.from(set)
this._index = -1
}
[Symbol.iterator]() {
let that = this
return {
next() {
that._index++
if (that._index >= that._entries.length) {
return {
done: true
}
}
return {
value: that._entries[that._index],
done: false
}
},
hasNext() {
return that._index < that._entries.length - 1
},
size: that._entries.length
}
}
getLength() {
return this._entries.length
}
toArray() {
return Array.from(this._entries)
}
}
module.exports = Collection
let Collection = require("./Collection.js")
class Tang extends Collection {
constructor(arr) {
super(arr)
}
equals(tang, compare) {
if (!Tang.isTang(tang)) {
throw new Error('222222')
}
if (!compare) {
compare = (a, b) => a === b
}
let arra = this._entries
let arrb = tang._entries
if (arra.length !== arrb.length) {
return false
}
arrb.forEach(item => {
for (let i = 0; i < arra.length; i++) {
if (compare(item, arra[i])) {
break;
}
}
return false
})
return true
}
contains(lit, compare) {
}
static isTang(obj) {
return obj.constructor.name == "Tang"
}
}
module.exports = Tang
let factorial = function factorial(num) {
if (num === 0) {
return 1
}
let result = 1
while (num > 0) {
result *= num
num--
}
return result
}
// Discrete Math
// Combinations Calculator
let com = function com(n, k) {
return factorial(n) / (factorial(k) * factorial(n - k))
}
// Combinations Replacement Calculator
let com2 = function com2(n, k) {
return com(n + k + 1, n - 1)
}
// Permutations Calculator
let permutation = function permutation(n, k) {
return factorial(n) / factorial(n - k)
}
// Permutations Replacement Calculator
let permutation2 = function permutation2(n, k) {
return n ** k
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment