JavaScript の Plain Object (ただの) と、関数のみを利用して、Polymorphism を実現したい。
とはいえ Polymorphism の定義は人によって違うので、以下の仕様とルールを満たすものとしたい。
そもそもそれは Polymorphism ではない、あるいは意味をなさない、というような反論があればそれも歓迎。
# A patch for faraday raise_error middleware for my usecase | |
# faraday: https://github.com/lostisland/faraday | |
class Connection | |
def self.foo_service | |
Thread.current[:foo_connection] ||= Faraday.new(Rails.application.config.x.foo_service_url) do |conn| | |
conn.request :json | |
conn.response :my_raise_error # See below comment | |
conn.response :json, :content_type => /\bjson$/ |
abstract class A<T> { | |
a() { return new Map<string, T>(); } | |
static b(): number { return 1; } | |
} | |
class X<T> extends A<T> {} | |
class Y extends A<number> {} | |
new X<number>().a(); // OK | |
new Y().a(); // OK | |
X.b(); // OK |
const assert = require('assert'); | |
const _ = require('lodash'); | |
class Masu { | |
constructor(isMine, isOpened) { | |
this.isMine = isMine; | |
this.isOpened = isOpened; | |
} | |
} |
import assert from 'assert'; | |
type State = [number, number, number, number]; | |
function stateToHashNum(state: State): number { | |
const [x1, x2, y1, y2] = state; | |
return (x1 << 9) | (x2 << 6) | (y1 << 3) | y2; | |
} | |
function hashNumToState(num: number): State { |
import React from 'react'; | |
import './App.css'; | |
import { Client } from 'boardgame.io/react'; | |
import { Game, IPlayer, IGameCtx } from 'boardgame.io/core'; | |
import { AI, IAIMoveObj } from 'boardgame.io/ai'; | |
type GameState = { | |
cells: Array<IPlayer | null> | |
}; |
ダンボー田中vs軍曹関の設計トークバトル! ひゃたもあるよ
# 22 引数に配列をとって、重複している値を昇順の配列にして返す関数を作れ。 | |
# 例)引数 [1, 3, 2, 3, 8, 3, 2] => 返り値 [2, 3] | |
def q22(array) | |
dup = {} # key: number, value: duplicate count (2以上のときは2) | |
ans = [] | |
array.each do |num| | |
case dup[num] | |
when nil | |
dup[num] = 1 |
Faraday::NestedParamsEncoder.encode({"a"=>[{"b"=>"1", "c"=>"2"}, {"b"=>"3", "c"=>"4"}]}) | |
# => "a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bb%5D=3&a%5B%5D%5Bc%5D=4" | |
URI.decode('a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bb%5D=3&a%5B%5D%5Bc%5D=4') | |
# => "a[][b]=1&a[][c]=2&a[][b]=3&a[][c]=4" | |
Faraday::NestedParamsEncoder.encode({"a"=>[{"b"=>"1", "c"=>"2"}, {"d"=>"3", "e"=>"4"}]}) | |
# => "a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bd%5D=3&a%5B%5D%5Be%5D=4" | |
URI.decode("a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bd%5D=3&a%5B%5D%5Be%5D=4") | |
# => "a[][b]=1&a[][c]=2&a[][d]=3&a[][e]=4" | |
Faraday::NestedParamsEncoder.decode("a%5B%5D%5Bb%5D=1&a%5B%5D%5Bc%5D=2&a%5B%5D%5Bd%5D=3&a%5B%5D%5Be%5D=4") |