Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
meeko
Advanced tools
Readme
npm i meeko
npm run jsdoc
jsdoc 对 BigInt 解析存在问题,我的修复方案 https://github.com/jsdoc/jsdoc/issues/1918#issuecomment-1104054464
const $ = require('meeko')
// 1024^1024 各个个位数分布 统计分析
let a = [315, 302, 300, 337, 289, 304, 299, 327, 304, 306]
console.log('平均数', $.math.mean(a))
console.log('方差', $.math.variance(a))
console.log('更正方差', $.math.varianceCorrect(a))
console.log('标准偏差', $.math.stddev(a))
console.log('更正的标准差', $.math.stddevCorrect(a))
console.log('标准误差', $.math.stdErr(a))
console.log('变异系数', $.math.coeVariation(a))
console.log('最小', $.math.min(a))
console.log('最大', $.math.max(a))
console.log('范围', $.math.range(a))
console.log('中位数', $.math.median(a))
console.log('平均偏差', $.math.meanDev(a))
console.log('中位数偏差', $.math.medianAbsDev(a))
console.log('调和平均数', $.math.hMean(a))
console.log('几何平均数', $.math.gMean(a))
console.log('偏度', $.math.skew(a, true))
// 傅里叶分析
$.math.fourierAnalysis([1, 2, 1, 2, 1, 2, 1, 2])
import * as $ from 'meeko'
// meeko无依赖的,决策树学习
const data = [
['色泽', '根蒂', '敲声', '纹理', '脐部', '触感', '好坏'],
['青绿', '蜷缩', '浊响', '清晰', '凹陷', '硬滑', '好瓜'],
['乌黑', '蜷缩', '沉闷', '清晰', '凹陷', '硬滑', '好瓜'],
['乌黑', '蜷缩', '浊响', '清晰', '凹陷', '硬滑', '好瓜'],
['青绿', '蜷缩', '沉闷', '清晰', '凹陷', '硬滑', '好瓜'],
['浅白', '蜷缩', '浊响', '清晰', '凹陷', '硬滑', '好瓜'],
['青绿', '稍蜷', '浊响', '清晰', '稍凹', '软粘', '好瓜'],
['乌黑', '稍蜷', '浊响', '稍糊', '稍凹', '软粘', '好瓜'],
['乌黑', '稍蜷', '浊响', '清晰', '稍凹', '硬滑', '好瓜'],
['乌黑', '稍蜷', '沉闷', '稍糊', '稍凹', '硬滑', '坏瓜'],
['青绿', '硬挺', '清脆', '清晰', '平坦', '软粘', '坏瓜'],
['浅白', '硬挺', '清脆', '模糊', '平坦', '硬滑', '坏瓜'],
['浅白', '蜷缩', '浊响', '模糊', '平坦', '软粘', '坏瓜'],
['青绿', '稍蜷', '浊响', '稍糊', '凹陷', '硬滑', '坏瓜'],
['浅白', '稍蜷', '沉闷', '稍糊', '凹陷', '硬滑', '坏瓜'],
['乌黑', '稍蜷', '浊响', '清晰', '稍凹', '软粘', '坏瓜'],
['浅白', '蜷缩', '浊响', '模糊', '平坦', '硬滑', '坏瓜'],
['青绿', '蜷缩', '沉闷', '稍糊', '稍凹', '硬滑', '坏瓜']
]
const tree1 = new $.ml.DecisionTree(data.slice(1), data[0])
tree1.printTree()
npm test
let $ = require('meeko')
Polynomial: x^3-3*x^2+2*x
Root:
x0: 0
x1: 1.000000
x2: 2.000000
Polynomial: 0.2*x^3+x^2+0.3*x-0.5
Root:
x0: 0.549510
x1: -1.000000
x2: -4.549510
Polynomial: x^2+1
Root:
x0: 0 +1.000000i
x1: 0 -1.000000i
Polynomial: x^3-1
Root:
x0: -0.500000 +0.866025i
x1: -0.500000 -0.866025i
x2: 1.000000
Polynomial: 3.13*x^2-2.21*x+5.99
Root:
x0: -0.353035 +1.337574i
x1: -0.353035 -1.337574i
Polynomial: x^5-5*x^3+5*x-1
Root:
x0: -1.827091
x1: -1.338261
x2: 1.000000
x3: 0.209057
x4: 1.956295
Polynomial: x^71-x^69-2*x^68-x^67+2*x^66+2*x^65+x^64-x^63-x^62-x^61-x^60-x^59+2*x^58+5*x^57+3*x^56-2*x^55-10*x^54-3*x^53-2*x^52+6*x^51+6*x^50+x^49+9*x^48-3*x^47-7*x^46-8*x^45-8*x^44+10*x^43+6*x^42+8*x^41-5*x^40-12*x^39+7*x^38-7*x^37+7*x^36+x^35-3*x^34+10*x^33+x^32-6*x^31-2*x^30-10*x^29-3*x^28+2*x^27+9*x^26-3*x^25+14*x^24-8*x^23-7*x^21+9*x^20+3*x^19-4*x^18-10*x^17-7*x^16+12*x^15+7*x^14+2*x^13-12*x^12-4*x^11-2*x^10+5*x^9+x^7-7*x^6+7*x^5-4*x^4+12*x^3-6*x^2+3*x-6
Look-and-say sequence
Root:
x0: -0.987974 +0.610013i
x1: -0.987974 -0.610013i
x2: -1.130898 +0.159772i
x3: -1.130898 -0.159772i
x4: -1.088244
x5: -1.011154
...
x68: 1.059674 +0.061938i
x69: 1.059674 -0.061938i
x70: 1.303577 Conway's constant
[1,2,3].intersect([3,4,5]) => [3]
[1,2,3].union([3,4,5]) => [1,2,3,4,5]
[1, 2, 3, 4].except([2, 3, 5]) => [1,4]
[2, 3, 5].except([1, 2, 3, 4]) => [5]
* $.dir(object)
* 内部10行代码实现 注意字符串下标数组无法显示
* 支持BigInt类型
let colWidth = [5, 10, 6]
let data = [
{ id: '1', b: 'aaa', c: 'cccc1' },
{ id: '2', b: 'bbb', c: 'cccc2' },
{ id: '3', b: 'ccc', c: 'cccc3' }
]
$.drawTable(data, colWidth)
let spinner = new $.Spinner('dots2')
spinner.start()
// '⣾⣽⣻⢿⡿⣟⣯⣷'
genDatetime // 产生起始日期-终止日期中间的日期 形式为 YYYY-MM-DD hh:mm:ss genDatetime('2016-1-1' '2016-2-2')
genData // 产生 指定字符串中用到的字符 返回指定长度 genData('abcdefghijklmnopqrstuvwxyz',10)
genName // 随机返回2-3的人名
genCard // 随机返回形式合格的身份码
genIp // 随机ip地址
genUrl // 随机返回 中间随机长度的 url genUrl(5)
genPhone // 随机返回 中国手机号码
genColor // 随机范围 hex颜色 和 rgba颜色 genColor('rgba')
genWord // 返回指定长度的中文常用字
genText // 返回指定长度的随机句子 >10才会有,。 也占1个汉字
genConstellation // 随机返回星座
genBool // 随机返回0,1`@genBool`
genEnum // 随机范围 数组的一个值 genEnum([1,2,3,'5x'])
$.log($.c.dimr('dimred', backGroundColor[41 - 47], isUnderline))
yyyy/YYYY mm/MM ww/WW dd/DD hh/HH mm ss SS(毫秒) q(季度) X(unix秒)
$.now().format('X')
其他对象会强制转化为String
注意, 不要设置默认值, 不是字符串, 有长度len判断时会有风险
[0, 1, true, false, '0', '1', 'true', 'false']都可以
isNumber 只接受浮点型,也不接受{},[]等内部转换
isBigInt 只接受 bigInt 型
isArray 只接受数组 t 型
isNull 只接受 null 型
isUndefined 只接受 undefined 型
isRegExp 只接受正则型
isDecimal 泛浮点型
[null, undefined, 正则, 布尔值, {}, []]不可以
可以化为数值的字符串 可以, 但类似 '1x' 不可以
同isDecimal 原则
可以化为日期的字符串,日期型都可以。日期型没意义因为初始化就确定时间了,日期字
符型必须有 “/” 或者 “-”
#now() 作为默认值代表 当前时间
增加 enum类型,def不起作用 size设置不能为空,且为数组
[1, 2, 3, 4, 5].remove(1,2) => [1,4,5]
['A', 'B', 'B', 'C', 'A', 'D'].count() => {"A":2,"B":2,"C":1,"D":1}
[1, [2, [3, [4, 5], 6], 7], 8].flatten() => [1,2,3,4,5,6,7,8]
[{ name: 'A', age: 48 }, { name: 'B', age: 36 }, { name: 'C', age: 26 }]
.orderBy(['age'],['asc'])
=> [{"name":"C","age":26},{"name":"B","age":36},{"name":"A","age":48}] 默认升序
$.tools.checkParam(obj)
* obj 如果为日期格式,日期格式为UTC日期
* 请在前端写入mysql之前 date.date2Str()一下
* 否则需要主动调用mysql的转换utc时间的函数
r = '(你|我|他)'
console.log($.reg.gen(r))
$.requireAll() // 加载某个目录下的所有对象,默认 __dirname
new $.Snowflake(workId, dataCenterId, sequence) // 工作进程id ,服务器id,开始序号
let r = $.pipe(x => x.toUpperCase(), ------单词变大写
a => a.split(''), --------------------分成数组
a => a[3], ---------------------------取下标3
s => s.charCodeAt(0).toString(16), ---变为16进制
s => s.fillStr('0', 4, -1), ----------不足4位部分左边填0
s => `\\u${s}` -----------------------转成\uxxxx 形式
)('Test') ------------------------------ => \u0054
function thenFunc() {
let me = this
me.then = async function (resolve, reject) {
await $.wait(2000)
resolve('success')
reject('failure')
console.log(2)
}
me.a1 = 'a1'
return me
}
async function init() {
try {
let r = new thenFunc()
await r
console.log(11, r)
} catch (err) {
console.log(err)
}
}
init()
process.on('unhandledRejection', function (e) {
console.log(e, 'xxx')
})
https://gitmoji.carloscuesta.me/
// 小明玩王者荣耀胜率为50% 每天玩10局,问每天小明连胜3局以上的概率是多少?
// 解法一
const $ = require('meeko')
const times = 3000000 // 总模拟次数
console.log(
'10'
.repeat(times / 2)
.split('') // 填入一半1 一半0
.fisherYates() // 洗牌算法
.chunk(10) // 按10个一组分组,每天10局
.filter(item => /1{3,10}/g.test(item.join(''))).length / // 找出10次内满足 3次-10次连胜的情况
(times / 10) // 换算到每天
)
// 0.5080 => 50%
// 解法二
/**
* 样本空间 10
* 胜利概率 1/2 成功 失败
* 目标 大于连续三次胜利
*/
function 获取大于连续三次胜利概率(测试次数 = 10000) {
let 测试通过 = 0
function 玩一天() {
胜利次数 = 0
for (let i = 0; i < 10; i++) {
if (成功吗()) {
if (++胜利次数 === 3) return 测试通过++
} else {
胜利次数 = 0
}
}
}
for (let i = 0; i < 测试次数; i++) 玩一天()
return 测试通过 / 测试次数
}
function 成功吗() {
return Math.random() > 0.5
}
function 单元测试__成功吗() {
let 测试通过 = 0
let 测试次数 = 1000
for (let i = 0; i < 测试次数; i++) {
if (成功吗()) 测试通过++
}
return 测试通过 / 测试次数
}
// 获取大于连续三次胜利概率()
// 最终解法 520 / 1024
// 一个自然数将它的末尾数字移到首位,得到的新数是原数的2倍,求这个自然数
let [n, mod] = [0n, 1n]
while (mod !== 0n) {
n = n + 1n
mod = ((20n * 10n ** n - 4n) * 10n) % 19n
}
console.log('结果:', ((20n * 10n ** n - 4n) * 10n) / 19n + 2n)
// 105263157894736842n
/*
编写完成分数转小数函数fraction2decimal
输入2个正整数(<2^52),输出小数,如有循环节 用[]框出,
例如 1,7=> 0.[142857] 13,90=> 0.1[4] 1,1=>1
普通要求:代码控制在20行内,15分钟完成
更高要求:代码控制在10行内,算法复杂度O(N)
*/
某百货超市现有一批快到期的日用产品急需处理,超市老板设计了免费抽奖活动来处理掉了这些商品纸箱中装有大小相同的 20 个球,10 个 10 分,10 个 5 分,从中摸出 10 个球,摸出的 10 个球的分数之和即为中奖分数,获奖如下:一等奖 100 分,冰柜一个,价值 2500 元;二等奖 50 分, 电视机一个,价值 1000 元;三等奖 95 分, 洗发液 8 瓶,价值 176 元;四等奖 55 分, 洗发液 4 瓶,价值 88 元;五等奖 60 分, 洗发液 2 瓶,价值 44 元;六等奖 65 分, 牙膏一盒, 价值 8 元;七等奖 70 分, 洗衣粉一袋,价值 5 元;八等奖 85 分, 香皂一块, 价值 3 元;九等奖 90 分, 牙刷一把, 价值 2 元;十等奖 75 分与 80 分为优惠奖,只収成本价 22 元,将获得洗发液一瓶
const $ = require('meeko')
let cof = [1000, 88, 44, 8, 5, -22, -22, 3, 2, 178, 2500]
let baseCount = $.math.combination(20, 10)
let EX = cof.reduce((a, b, idx) => {
let r = ($.math.combination(10, idx) * $.math.combination(10, 10 - idx)) / baseCount
return a + r * b
}, 0)
console.log(EX) //-10.095141700404858
FAQs
meeko自用函数
The npm package meeko receives a total of 171 weekly downloads. As such, meeko popularity was classified as not popular.
We found that meeko demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.