sequence関係のユーティリティ関数で自分がよく知らないものをまとめておく。
昔はindexed
っていうそのまんまな関数があったけど、1.3くらいからなくなっていた。今はmap-indexed
っていう関数を使う。よく使うのはこんな感じの使い方。
(map-indexed #(vector %1 %2) ["a" "b" "c" "d" "e"])
; ([0 "a"] [1 "b"] [2 "c"] [3 "d"] [4 "e"])
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna! | |
([一-龯]) | |
Regex for matching Hirgana or Katakana | |
([ぁ-んァ-ン]) | |
Regex for matching Non-Hirgana or Non-Katakana | |
([^ぁ-んァ-ン]) | |
Regex for matching Hirgana or Katakana or basic punctuation (、。’) |
;;; defn で関数の定義。引数は [] で囲む | |
(defn hello-work [a, b] | |
;; format を使うと printf ライクに書ける | |
(println (format "hello work %s %s" a, b))) | |
;;; 純粋 Lisp は空白を区切りとして扱うが、Clojure は「 , も空白として扱う」らしい | |
;;; 下記は両方とも意味は同じ | |
(hello-work "comma", "test") | |
(hello-work "space" "test") |
/** | |
* @see http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx | |
*/ | |
<script type="text/jscript" language="javascript"> | |
function getQuerystring(key, default_) | |
{ | |
if (default_==null) default_=""; | |
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); | |
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)"); | |
var qs = regex.exec(window.location.href); |
/** | |
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers | |
* @author ShirtlessKirk. Copyright (c) 2012. | |
* @license WTFPL (http://www.wtfpl.net/txt/copying) | |
*/ | |
var luhnChk = (function (arr) { | |
return function (ccNum) { | |
var | |
len = ccNum.length, | |
bit = 1, |
// Takes a credit card string value and returns true on valid number | |
function valid_credit_card(value) { | |
// Accept only digits, dashes or spaces | |
if (/[^0-9-\s]+/.test(value)) return false; | |
// The Luhn Algorithm. It's so pretty. | |
let nCheck = 0, bEven = false; | |
value = value.replace(/\D/g, ""); | |
for (var n = value.length - 1; n >= 0; n--) { |
2013 Minori Yamashita ympbyc@gmail.com
ターゲットを動的オブジェクト指向プログラマに絞って、関数指向の考え方を説明します。 コードサンプルでは、オブジェクト指向には CoffeeScript ^1、関数指向には Clojure を使用しますが、文章は汎用的に書いてあります。
最下部に用語集があるので、わかりづらい単語、表現があったら参照してください。