Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <ul>
    <li>A</li>
    <li>B</li>
    <li>C</li>
  </ul>
  <script>
    // fn.coffee.min.js
    var add,all,any,apply,builtin,compact,compose,concatF,countBy,curry,difference,div,drop,dups,each,even,filter,first,flatMap,flatten,flip,flip3,flipN,fold,forOwn,gmatch,groupBy,gt,gte,has,id,inArray,initial,instanceOf,intersection,isF,isType,isntF,join,keys,last,lt,lte,map,match,max,min,mod,mul,nop,notF,odd,pairs,partial,partition,pluck,pluckR,reject,replace,rest,reverse,search,sequence,size,slice,sortBy,split,sub,substr,take,toLower,toObject,toUpper,trim,union,unique,unwords,unzipObject,values,variadic,where,withF,words,zip,zipObject,zipWith,_,__slice=[].slice,__indexOf=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++){if(t in this&&this[t]===e)return t}return-1},__hasProp={}.hasOwnProperty;_={};nop=function(){};id=function(e){return e};builtin=function(e){return nop.call.bind(e)};variadic=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return e};apply=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return t.apply(null,[].concat.apply([],e))};notF=function(e){return function(){var t;t=1<=arguments.length?__slice.call(arguments,0):[];return!e.apply(null,t)}};curry=function(e){var t;return(t=function(n){var r;r=function(){var r,i;i=1<=arguments.length?__slice.call(arguments,0):[];r=(n||[]).slice(0);if(r.push.apply(r,i)<e.length&&i.length){return t(r)}return e.apply(null,r)};if(e.length>1){return r}else{return e}})()};partial=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return function(){var n,r,i;r=1<=arguments.length?__slice.call(arguments,0):[];n=e.concat(r);i=n.length;while(i--){if(n[i]===_){n[i]=n.splice(-1)[0]}}return t.apply(null,n)}};flip=curry(function(e,t,n){return e.apply(null,[n,t])});flip3=curry(function(e,t,n,r){return e.apply(null,[r,n,t])});flipN=function(e){return function(){var t;t=1<=arguments.length?__slice.call(arguments,0):[];return e.apply(null,t.reverse())}};compose=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return e.reduce(function(e,t){return function(){var n;n=1<=arguments.length?__slice.call(arguments,0):[];return e(t.apply(null,n))}})};sequence=flipN(compose);isType=curry(function(e,t){return Object.prototype.toString.call(t).slice(8,-1)===e});instanceOf=curry(function(e,t){return t instanceof e});isF=curry(function(e,t){return e===t});isntF=notF(isF);gt=curry(function(e,t){return t>e});lt=notF(gt);gte=curry(function(e,t){return t>=e});lte=curry(function(e,t){return t<=e});each=flip(builtin(Array.prototype.forEach));map=flip(builtin(Array.prototype.map));filter=flip(builtin(Array.prototype.filter));fold=flip3(builtin(Array.prototype.reduce));all=flip(builtin(Array.prototype.every));any=flip(builtin(Array.prototype.some));reverse=builtin(Array.prototype.reverse);join=builtin(Array.prototype.join);split=flip(builtin(String.prototype.split));match=flip(builtin(String.prototype.match));replace=flip3(builtin(String.prototype.replace));search=flip(builtin(String.prototype.search));substr=flip3(builtin(String.prototype.substr));trim=builtin(String.prototype.trim);toUpper=builtin(String.prototype.toUpperCase);toLower=builtin(String.prototype.toLowerCase);inArray=curry(function(e,t){return __indexOf.call(t,e)>=0});slice=curry(function(e,t,n){if(t!=null){return n.slice(e,t)}else{return n.slice(e)}});first=function(e){var t,n;t=e[0],n=2<=e.length?__slice.call(e,1):[];return t};last=function(e){var t,n,r;n=2<=e.length?__slice.call(e,0,r=e.length-1):(r=0,[]),t=e[r++];return t};rest=slice(1,null);initial=slice(0,-1);take=slice(0);drop=partial(slice,_,null,_);words=split(" ");unwords=join(" ");reject=curry(function(e,t){return filter(notF(e),t)});compact=filter(Boolean);unique=function(e){return e.filter(function(t,n){return e.indexOf(t)===n})};dups=function(e){return e.filter(function(t,n){return e.indexOf(t)!==n})};flatten=function(e){return e.reduce(function(e,t){if([].concat(t).some(Array.isArray)){return e.concat(flatten(t))}return e.concat(t)},[])};flatMap=flip(compose(flatten,map));union=compose(unique,flatten,variadic);intersection=compose(unique,dups,flatten,variadic);partition=curry(function(e,t){return[filter(e,t),reject(e,t)]});difference=function(){var e,t;t=arguments[0],e=2<=arguments.length?__slice.call(arguments,1):[];return reject(inArray(unique(flatten(e))),t)};withF=curry(function(e,t){return compose(partial(apply,t),map(e),variadic)});concatF=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return function(t){return e.reduce(function(e,n,r){e[r]=n(t);return e},[])}};toObject=function(e){return e.reduce(function(t,n,r){if(r%2!==0){t[e[r-1]]=n}return t},{})};forOwn=curry(function(e,t,n){var r,i;r=0;for(i in n){if(!__hasProp.call(n,i))continue;e=t.apply(null,[e,i,n[i],r++])}return e});pluck=curry(function(e,t){return String(e).split(".").reduce(function(e,t){if(t in Object(e)){return e[t]}else{return void 0}},t)});pluckR=curry(function(e,t){var n;n=[];while(t=pluck(e,t)){n.push(t)}return n});pairs=forOwn([],function(e,t,n){e.push([t,n]);return e});zip=function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return e[0].map(function(t,n){return e.map(function(e){return e[n]})})};zipWith=function(){var e,t;e=arguments[0],t=2<=arguments.length?__slice.call(arguments,1):[];return map(partial(apply,e),apply(zip,t))};zipObject=compose(toObject,flatten,zip);unzipObject=forOwn([[],[]],function(e,t,n,r){e[0][r]=t;e[1][r]=n;return e});keys=Object.keys;values=compose(pluck(1),unzipObject);size=compose(pluck("length"),keys);has=compose(notF(isType("Undefined")),pluck);where=curry(function(e,t){return t.filter(function(t){return Object.keys(e).every(function(n){return e[n]===t[n]})})});sortBy=curry(function(e,t){return t.sort(withF(e,function(e,t){if(typeof e==="number"){return e-t}else if(e>t){return 1}else if(e<t){return-1}else{return 0}}))});groupBy=curry(function(e,t){return t.reduce(function(t,n){var r;r=e(n);t[r]=(t[r]||[]).concat(n);return t},{})});countBy=sequence(groupBy,forOwn(function(e,t,n){e[t]=n.length;return e}));gmatch=curry(function(e,t){var n;n=[];t.replace(e,function(){var e;e=1<=arguments.length?__slice.call(arguments,0):[];return n.push.apply(n,e.slice(1,-2))});return n});mod=curry(function(e,t){return t%e===0});even=mod(2);odd=notF(even);add=curry(function(e,t){return e+t});sub=curry(function(e,t){return t-e});mul=curry(function(e,t){return e*t});div=curry(function(e,t){return t/e});min=partial(apply,Math.min);max=partial(apply,Math.max)
  </script>  
</body>
</html>
 
toArray = builtin Array::slice
query = curry (el, sel) -> toArray el.querySelectorAll sel
$ = query document
$.map = compose compact, unique, flatten, map
parent = pluck 'parentNode'
parents = pluckR 'parentNode'
children = compose toArray, pluck 'children'
nextAll = pluckR 'nextElementSibling'
prevAll = pluckR 'previousElementSibling'
siblings = concatF prevAll, nextAll
tag = pluck 'tagName'
text = pluck 'textContent'
html = pluck 'innerHTML'
console.log $.map children, $ 'ul' #=> [li, li, li]
console.log $.map parents, $ 'li' #=> [ul, body, html, document]
console.log filter compose(isF('UL'), tag), $.map parents, $ 'li' #=> [ul]
console.log $.map text, $ 'li' #=> ['A', 'B', 'C']
console.log first $.map compose(trim, html), $ 'ul' #=> '<li>A</li>\n<li>B</li>\n<li>C</li>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
elclanrspro
0viewers