Skip to content

Standard Library Cheatsheet

Anthony Fu edited this page Jan 17, 2020 · 4 revisions

Last updated: Fri, 17 Jan 2020 18:42:31 GMT

Usage

吾嘗觀「「算經」」之書。方悟「正弦」「餘弦」「圓周率」之義。

Table of Contents

Wenyan Javascript Equivalent
遍施 Array.forEach
篩剔 Array.filter
排序 Array.sort
倒序 Array.reverse
擷取 Array.slice
Wenyan Javascript Equivalent

💬 This library uses your system timezone setting

Wenyan Javascript Equivalent
今何紀元時 Date.now() / 1000
言今之日時 new Date().toString(), in Chinese calendar
言今之年月日 new Date().toDateString(), in Chinese calendar
言今之時刻 new Date().toTimeString(), in Chinese calendar
今年何年號 "西元" for modern dates
今年何年 new Date().getFullYear() for modern dates, in Chinese calendar
今年何干支 Get index (1 to 60) of this year in the 60-year cycle
今年積何年 new Date().getFullYear() + 2697, in Chinese calendar
今月何月 new Date().getMonth() + 1, N + 0.5 for leap months, in Chinese calendar
今月積何月 Get continuously counting month number of this month
今日何日 new Date().getDate(), in Chinese calendar
今日何干支 Get index (1 to 60) of today in the 60-day cycle
今日積何日 Get continuously counting day number of today
今時何時 Get index (1 to 12) of current time in the 12 divisions of day
今時何小時 new Date().getHours()
今刻何刻 Math.floor(new Date().getMinutes() / 15)
今分何分 new Date().getMinutes() % 15
今秒何秒 new Date().getSeconds()
言彼之日時 new Date(x * 1000).toString(), in Chinese calendar
言彼之年月日 new Date(x * 1000).toDateString(), in Chinese calendar
言彼之時刻 new Date(x * 1000).toTimeString(), in Chinese calendar
彼年何年號 "西元" for modern dates
彼年何年 new Date(x * 1000).getFullYear() for modern dates, in Chinese calendar
彼年何干支 Get index (1 to 60) in the 60-year cycle
彼年積何年 new Date(x * 1000).getFullYear() + 2697, in Chinese calendar
彼月何月 new Date(x * 1000).getMonth() + 1, N + 0.5 for leap months, in Chinese calendar
彼月積何月 Get continuously counting month number
彼日何日 new Date(x * 1000).getDate(), in Chinese calendar
彼日何干支 Get index (1 to 60) in the 60-day cycle
彼日積何日 Get continuously counting day number
彼時何時 Get index (1 to 12) in the 12 divisions of day
彼時何小時 new Date(x * 1000).getHours()
彼刻何刻 Math.floor(new Date(x * 1000).getMinutes() / 15)
彼分何分 new Date(x * 1000).getMinutes() % 15
彼秒何秒 new Date(x * 1000).getSeconds()
Wenyan Javascript Equivalent
圓周率 Math.PI
倍圓周率 Math.PI * 2
半圓周率 Math.PI / 2
四分圓周率 Math.PI / 4
自然常數 Math.E
歐拉常數 0.5772156649015329
黃金分割數 1.618033988749895
二之平方根 Math.SQRT2
二之對數 Math.LN2
十之對數 Math.LN10
不可算數乎 Number.isNaN
浮點移位 x * Math.pow(2, y), y is integer
析浮點數 N/A
取底除 { 商: Math.floor(x / y), 餘: x - y * quo }
取整除 { 商: Math.round(x / y), 餘: x - y * quo }
正弦 Math.sin
餘弦 Math.cos
反正弦 Math.asin
反餘弦 Math.acos
正切 Math.tan
反正切 Math.atan
勾股求角 Math.atan2
勾股求弦 Math.hypot
對數 Math.log
指數 Math.exp
Math.pow
平方根 Math.sqrt
絕對 Math.abs
取頂 Math.ceil
取底 Math.floor
取整 Math.round, but rounded away from zero when the fractional part is exactly 0.5
捨餘 Math.trunc
正負 Math.sign
Wenyan Javascript Equivalent
求和 reduce((a,b)=>a+b)
Wenyan Javascript Equivalent
Wenyan Javascript Equivalent
Wenyan Javascript Equivalent

Help update this cheatsheet

This cheatsheet is generated direct from stdlibs. There are still a lot of functions are not listed above. If you would like to hep update this cheatsheet, here is the steps.

Add comments in the stdlib files (one line above the function/value), the format should look like this:

注曰「「餘弦。同Javascript之Math.cos也。」」

After you fill the comments, commit and open a pull request. Thank you!