JSFiddle - React, Tailwind, and code Playground

by naokiota

HTML

<script src="http://rubyjs.org/reloaded/ruby.min.js"></script>
<!-- Including "ruby.min.js" as an External Resources -->

JavaScript

// RubyJS (Lite)
console.log(_s.capitalize("foo"))      // => "Foo"
// RubyJS (Classic)
console.log(R("foo").capitalize())// => {R.String: "Foo"}

/*
  1. 配列に格納された文字列を数値に変換する
*/

// JSの場合
console.log(['10', '10', '10'].map(parseInt));     // => [10, NaN, 2](失敗)
console.log(['10', '10', '10'].map(parseInt.bind(null, 10)));// => [10, 10, 10]
console.log(['10', '10', '10'].map(Number));// => [10, 10, 10]

//underscoreの場合
console.log("underscore.js",_.map(['10', '10', '10'],parseInt.bind(null, 10)));
console.log("underscore.js",_.map(['10', '10', '10'],Number));

// RubyJSの場合
console.log(_a.map(['10', '10', '10'], parseInt)); // => [10, 10, 10]
console.log(_a.map(['10', '10', '10'], parseInt)); // => [10, 10, 10]

// 配列に格納された数値をソートする
// JSの場合
console.log("JS",[33,4,1111,222].sort());     // => [1111,222,33,4]
console.log("JS",[33,4,1111,222].sort(function(a,b){ return a - b;}));     // => [1, 15, 8]
console.log("underscore",_.sortBy([33,4,1111,222], function(num){ return num; }));
// RubyJSの場合
console.log("RubyJS",_a.sort([8, 1, 15]));   // => [1, 8, 15]