Skip to content

Instantly share code, notes, and snippets.

View ikasoba's full-sized avatar
貴様ッ!見ているなッ!

ikasoba ikasoba

貴様ッ!見ているなッ!
View GitHub Profile
@ikasoba
ikasoba / kanToNum.js
Last active February 8, 2022 05:41
漢数字を整数に
// 漢字で表した整数を整数の数値として返す
const kanToNum = (knum="三百二十一")=>{
const or=(a,b)=>a==null ? b : a;
const numb = new Map()
.set("零",0).set("一",1).set("二",2).set("三",3).set("四",4)
.set("五",5).set("六",6).set("七",7).set("八",8).set("九",9);
const places = new Map()
.set("十",10).set("百",100).set("千",1000).set("万",10000)
.set("億",10**8).set("兆",10**12).set("京",10**16).set("垓",10**20);
@ikasoba
ikasoba / calc.js
Last active February 7, 2022 14:41
順序なし、整数のみの計算式の文字列を実行します(evalの計算だけ版のようなもの)。実数はフリーズします
const calc=((raw)=>{
let s=[]
const sw = (addIndex,v,f)=>new class {
cases=new Map();
def=null;
c(v,f){
this.cases.set(v,f)
return this
}
d(f){
@ikasoba
ikasoba / r.js
Last active March 7, 2022 12:08
正規表現オブジェクトをタグ付きテンプレートリテラルから作るやつ / The one that creates regular expression objects from tagged template literals.
/*MIT License
Copyright 2022 ikasoba
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE US
@ikasoba
ikasoba / calc.js
Created February 8, 2022 05:40
順序あり(多分)、正負の数値(実数あり)の計算式を計算するJavaScriptの関数
const calc=((raw)=>{
const sw = (addIndex,v,f)=>new class {
cases=new Map();
def=null;
c(v,f){
this.cases.set(v,f)
return this
}
d(f){
this.def=f
@ikasoba
ikasoba / genCharsFromAToB.js
Last active February 22, 2022 13:54
aからbまでの文字列を生成します "a"と"z"を指定したら小文字のアルファベットを出力します。 / Generate a string from a to b. Given "a" and "z", output the lowercase alphabet.
const genCharsFromAToB=(a,b)=>Array.from({length:b.charCodeAt(0)-a.charCodeAt(0)+1},(_,i)=>String.fromCharCode(a.charCodeAt(0)+i))
@ikasoba
ikasoba / getProperty.js
Last active March 4, 2022 10:12
再帰的にプロパティを取ってくるくん 1号
/**
* @return {any|null|undefined}
* @example
* getProperty(
* "posts[0].content",
* {
* posts:[
* {
* content:"hogehoge"
* }
@ikasoba
ikasoba / saikiRange.js
Last active April 5, 2022 06:40
Typescriptの再帰型の練習に再帰的にn~0までArray。range(10)としたら10~0の長さ11の配列が出来上がります。
export const range = (i=0)=>[i,...([()=>range(i-1),()=>[]][~~(i<=0)]())]
@ikasoba
ikasoba / range.ts
Created March 5, 2022 09:31
typescriptで0~(n-1)までの整数値のみ型
type Append<T extends any[],U extends any> = [...T,U]
type range<N extends number,A extends any[]> = {
0:range<N,Append<A,A["length"]>>,
1:A
}[A["length"] extends N ? 1 : 0]
const nums:range<4,[]>=[0,1,2,3]
console.log(nums)
@ikasoba
ikasoba / type_calculator.ts
Last active March 5, 2022 12:36
typescriptの型で計算機
export type Down<A> = A extends [null, ...null[]]
? ((..._: A) => null) extends (_:null, ...a:infer T) => null
? T
: never
: never
export type Up<A extends null[],B extends null|null[] = null> = [...A,...(B extends null ? [B] : B)]
export type Num<N extends number,A extends null[] = []> = {
0:A,
@ikasoba
ikasoba / fizzBuzz1l.js
Last active March 6, 2022 08:04
fizz buzzをワンライナーで書いた
Array.from({length:500},(_,n)=>((i=n+1)=>(i%3==0) + (i%15==0) + (i%5==0)*2)()).map((x,i)=>x&1 ? "Fizz" : x&2 ? "Buzz" : x&4 ? "Fizz Buzz" : i+1).forEach((m)=>console.log(m))