Skip to content

Instantly share code, notes, and snippets.

@donnut
Last active August 29, 2015 14:07
Show Gist options
  • Save donnut/9a9d4f7b32c0a17e8ae4 to your computer and use it in GitHub Desktop.
Save donnut/9a9d4f7b32c0a17e8ae4 to your computer and use it in GitHub Desktop.
requirebin sketch
var R = require('ramda').installTo(this)
var a = {}
var b = {y: a}
var c = {z: b}
a.x = c
var refFrom = []
var refTo = []
var deepCopy = function(obj) {
if (is(Object, obj)) {
return copyObj(obj)
} else {
return obj
}
console.log('end', refTo)
}
var copyObj = function(obj) {
for (var key in obj) {
console.log(key)
if (is(Object, obj[key])) {
var i = findIndex(function(x) {return x === obj[key]}, refFrom)
if (i !== -1) {
console.log('stop', refFrom)
return refTo[i]
} else {
refFrom.push(obj[key])
var r = deepCopy(obj[key])
refTo.push(r)
console.log('returned: ',r)
return r
}
} else {
return obj
}
}
}
var z = deepCopy({a: {b:{c:1}}})
console.log('result', z)
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({ramda:[function(require,module,exports){(function(factory){if(typeof exports==="object"){module.exports=factory(this)}else if(typeof define==="function"&&define.amd){define(factory)}else{this.R=this.ramda=factory(this)}})(function(){"use strict";var R={version:"0.5.0"};function _slice(args,from,to){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return _slice(args,0,args.length);case 2:return _slice(args,from,args.length);default:var length=to-from,list=new Array(length),idx=-1;while(++idx<length){list[idx]=args[from+idx]}return list}}var concat=function _concat(set1,set2){set1=set1||[];set2=set2||[];var length1=set1.length,length2=set2.length,result=new Array(length1+length2);for(var idx=0;idx<length1;idx++){result[idx]=set1[idx]}for(idx=0;idx<length2;idx++){result[idx+length1]=set2[idx]}return result};var toString=Object.prototype.toString;var isArray=Array.isArray||function _isArray(val){return val&&val.length>=0&&toString.call(val)==="[object Array]"};R.isArrayLike=function isArrayLike(x){return isArray(x)||!!x&&typeof x==="object"&&!(x instanceof String)&&(!!(x.nodeType===1&&x.length)||x.length>=0)};var NO_ARGS_EXCEPTION=new TypeError("Function called with no arguments");function curry2(fn){return function(a,b){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return function(b){return fn(a,b)};default:return fn(a,b)}}}function curry3(fn){return function(a,b,c){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return curry2(function(b,c){return fn(a,b,c)});case 2:return function(c){return fn(a,b,c)};default:return fn(a,b,c)}}}if(typeof Object.defineProperty==="function"){try{Object.defineProperty(R,"_",{writable:false,value:void 0})}catch(e){}}var _=R._;void _;var op=R.op=function op(fn){var length=fn.length;if(length<2){throw new Error("Expected binary function.")}var left=curry(fn),right=curry(R.flip(fn));return function(a,b){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return right(a);case 2:return b===R._?left(a):left.apply(null,arguments);default:return left.apply(null,arguments)}}};var curryN=R.curryN=function curryN(length,fn){return function recurry(args){return arity(Math.max(length-(args&&args.length||0),0),function(){if(arguments.length===0){throw NO_ARGS_EXCEPTION}var newArgs=concat(args,arguments);if(newArgs.length>=length){return fn.apply(this,newArgs)}else{return recurry(newArgs)}})}([])};var curry=R.curry=function curry(fn){return curryN(fn.length,fn)};var hasMethod=function _hasMethod(methodName,obj){return obj&&!isArray(obj)&&typeof obj[methodName]==="function"};function checkForMethod(methodname,fn){return function(a,b,c){var length=arguments.length;var obj=arguments[length-1],callBound=obj&&!isArray(obj)&&typeof obj[methodname]==="function";switch(arguments.length){case 0:return fn();case 1:return callBound?obj[methodname]():fn(a);case 2:return callBound?obj[methodname](a):fn(a,b);case 3:return callBound?obj[methodname](a,b):fn(a,b,c)}}}var nAry=R.nAry=function(n,fn){switch(n){case 0:return function(){return fn.call(this)};case 1:return function(a0){return fn.call(this,a0)};case 2:return function(a0,a1){return fn.call(this,a0,a1)};case 3:return function(a0,a1,a2){return fn.call(this,a0,a1,a2)};case 4:return function(a0,a1,a2,a3){return fn.call(this,a0,a1,a2,a3)};case 5:return function(a0,a1,a2,a3,a4){return fn.call(this,a0,a1,a2,a3,a4)};case 6:return function(a0,a1,a2,a3,a4,a5){return fn.call(this,a0,a1,a2,a3,a4,a5)};case 7:return function(a0,a1,a2,a3,a4,a5,a6){return fn.call(this,a0,a1,a2,a3,a4,a5,a6)};case 8:return function(a0,a1,a2,a3,a4,a5,a6,a7){return fn.call(this,a0,a1,a2,a3,a4,a5,a6,a7)};case 9:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8){return fn.call(this,a0,a1,a2,a3,a4,a5,a6,a7,a8)};case 10:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){return fn.call(this,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9)};default:return fn}};R.unary=function _unary(fn){return nAry(1,fn)};var binary=R.binary=function _binary(fn){return nAry(2,fn)};var arity=R.arity=function(n,fn){switch(n){case 0:return function(){return fn.apply(this,arguments)};case 1:return function(a0){void a0;return fn.apply(this,arguments)};case 2:return function(a0,a1){void a1;return fn.apply(this,arguments)};case 3:return function(a0,a1,a2){void a2;return fn.apply(this,arguments)};case 4:return function(a0,a1,a2,a3){void a3;return fn.apply(this,arguments)};case 5:return function(a0,a1,a2,a3,a4){void a4;return fn.apply(this,arguments)};case 6:return function(a0,a1,a2,a3,a4,a5){void a5;return fn.apply(this,arguments)};case 7:return function(a0,a1,a2,a3,a4,a5,a6){void a6;return fn.apply(this,arguments)};case 8:return function(a0,a1,a2,a3,a4,a5,a6,a7){void a7;return fn.apply(this,arguments)};case 9:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8){void a8;return fn.apply(this,arguments)};case 10:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){void a9;return fn.apply(this,arguments)};default:return fn}};var invoker=R.invoker=function _invoker(name,obj,len){var method=obj[name];var length=len===void 0?method.length:len;return method&&curryN(length+1,function(){if(arguments.length){var target=Array.prototype.pop.call(arguments);var targetMethod=target[name];if(targetMethod==method){return targetMethod.apply(target,arguments)}}})};var useWith=R.useWith=function _useWith(fn){var transformers=_slice(arguments,1);var tlen=transformers.length;return curry(arity(tlen,function(){var args=[],idx=-1;while(++idx<tlen){args.push(transformers[idx](arguments[idx]))}return fn.apply(this,args.concat(_slice(arguments,tlen)))}))};function forEach(fn,list){var idx=-1,len=list.length;while(++idx<len){fn(list[idx])}return list}R.forEach=curry2(forEach);R.forEach.idx=curry2(function forEachIdx(fn,list){var idx=-1,len=list.length;while(++idx<len){fn(list[idx],idx,list)}return list});var clone=R.clone=function _clone(list){return _slice(list)};function isEmpty(list){return!list||!list.length}R.isEmpty=isEmpty;R.prepend=curry2(function prepend(el,list){return concat([el],list)});R.cons=R.prepend;R.head=function head(list){list=list||[];return list[0]};R.car=R.head;R.last=function _last(list){list=list||[];return list[list.length-1]};R.tail=checkForMethod("tail",function(list){list=list||[];return list.length>1?_slice(list,1):[]});R.cdr=R.tail;var append=R.append=curry2(function _append(el,list){return concat(list,[el])});R.push=R.append;R.concat=curry2(function(set1,set2){if(isArray(set2)){return concat(set1,set2)}else if(R.is(String,set1)){return set1.concat(set2)}else if(hasMethod("concat",set2)){return set2.concat(set1)}else{throw new TypeError("can't concat "+typeof set2)}});var identity=R.identity=function _I(x){return x};R.I=R.identity;R.times=curry2(function _times(fn,n){var list=new Array(n);var idx=-1;while(++idx<n){list[idx]=fn(idx)}return list});R.repeatN=curry2(function _repeatN(value,n){return R.times(R.always(value),n)});function internalCompose(f,g){return function(){return f.call(this,g.apply(this,arguments))}}var compose=R.compose=function _compose(){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return arguments[0];default:var idx=arguments.length-1,fn=arguments[idx],length=fn.length;while(idx--){fn=internalCompose(arguments[idx],fn)}return arity(length,fn)}};R.pipe=function _pipe(){return compose.apply(this,_slice(arguments).reverse())};var flip=R.flip=function _flip(fn){return function(a,b){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return function(b){return fn.apply(this,[b,a].concat(_slice(arguments,1)))};default:return fn.apply(this,concat([b,a],_slice(arguments,2)))}}};R.lPartial=function _lPartial(fn){var args=_slice(arguments,1);return arity(Math.max(fn.length-args.length,0),function(){return fn.apply(this,concat(args,arguments))})};R.rPartial=function _rPartial(fn){var args=_slice(arguments,1);return arity(Math.max(fn.length-args.length,0),function(){return fn.apply(this,concat(arguments,args))})};R.memoize=function _memoize(fn){if(!fn.length){return once(fn)}var cache={};return function(){if(!arguments.length){return}var position=foldl(function(cache,arg){return cache[arg]||(cache[arg]={})},cache,_slice(arguments,0,arguments.length-1));var arg=arguments[arguments.length-1];return position[arg]||(position[arg]=fn.apply(this,arguments))}};var once=R.once=function _once(fn){var called=false,result;return function(){if(called){return result}called=true;result=fn.apply(this,arguments);return result}};R.wrap=function _wrap(fn,wrapper){return function(){return wrapper.apply(this,concat([fn],arguments))}};var constructN=R.constructN=curry2(function _constructN(n,Fn){var f=function(){var Temp=function(){},inst,ret;Temp.prototype=Fn.prototype;inst=new Temp;ret=Fn.apply(inst,arguments);return Object(ret)===ret?ret:inst};return n>1?curry(nAry(n,f)):f});R.construct=function _construct(Fn){return constructN(Fn.length,Fn)};R.converge=function(after){var fns=_slice(arguments,1);return function(){var args=arguments;return after.apply(this,map(function(fn){return fn.apply(this,args)},fns))}};R.reduce=curry3(function _reduce(fn,acc,list){var idx=-1,len=list.length;while(++idx<len){acc=fn(acc,list[idx])}return acc});var foldl=R.foldl=R.reduce;R.reduce.idx=curry3(function _reduceIdx(fn,acc,list){var idx=-1,len=list.length;while(++idx<len){acc=fn(acc,list[idx],idx,list)}return acc});R.foldl.idx=R.reduce.idx;R.reduceRight=curry3(checkForMethod("reduceRight",function _reduceRight(fn,acc,list){var idx=list.length;while(idx--){acc=fn(acc,list[idx])}return acc}));R.foldr=R.reduceRight;R.reduceRight.idx=curry3(function _reduceRightIdx(fn,acc,list){var idx=list.length;while(idx--){acc=fn(acc,list[idx],idx,list)}return acc});R.foldr.idx=R.reduceRight.idx;R.unfoldr=curry2(function _unfoldr(fn,seed){var pair=fn(seed);var result=[];while(pair&&pair.length){result.push(pair[0]);pair=fn(pair[1])}return result});function map(fn,list){var idx=-1,len=list.length,result=new Array(len);while(++idx<len){result[idx]=fn(list[idx])}return result}R.map=curry2(checkForMethod("map",map));R.map.idx=curry2(function _mapIdx(fn,list){var idx=-1,len=list.length,result=new Array(len);while(++idx<len){result[idx]=fn(list[idx],idx,list)}return result});R.mapObj=curry2(function _mapObject(fn,obj){return foldl(function(acc,key){acc[key]=fn(obj[key]);return acc},{},keys(obj))});R.mapObj.idx=curry2(function mapObjectIdx(fn,obj){return foldl(function(acc,key){acc[key]=fn(obj[key],key,obj);return acc},{},keys(obj))});R.ap=curry2(function _ap(fns,vs){return hasMethod("ap",fns)?fns.ap(vs):foldl(function(acc,fn){return concat(acc,map(fn,vs))},[],fns)});R.of=function _of(x,container){return hasMethod("of",container)?container.of(x):[x]};R.empty=function _empty(x){return hasMethod("empty",x)?x.empty():[]};R.chain=curry2(checkForMethod("chain",function _chain(f,list){return unnest(map(f,list))}));R.size=function _size(list){return list.length};R.length=R.size;var filter=function _filter(fn,list){var idx=-1,len=list.length,result=[];while(++idx<len){if(fn(list[idx])){result.push(list[idx])}}return result};R.filter=curry2(checkForMethod("filter",filter));function filterIdx(fn,list){var idx=-1,len=list.length,result=[];while(++idx<len){if(fn(list[idx],idx,list)){result.push(list[idx])}}return result}R.filter.idx=curry2(filterIdx);var reject=function _reject(fn,list){return filter(not(fn),list)};R.reject=curry2(reject);R.reject.idx=curry2(function _rejectIdx(fn,list){return filterIdx(not(fn),list)});R.takeWhile=curry2(checkForMethod("takeWhile",function(fn,list){var idx=-1,len=list.length;while(++idx<len&&fn(list[idx])){}return _slice(list,0,idx)}));R.take=curry2(checkForMethod("take",function(n,list){return _slice(list,0,Math.min(n,list.length))}));R.skipUntil=curry2(function _skipUntil(fn,list){var idx=-1,len=list.length;while(++idx<len&&!fn(list[idx])){}return _slice(list,idx)});R.skip=curry2(checkForMethod("skip",function _skip(n,list){if(n<list.length){return _slice(list,n)}else{return[]}}));R.find=curry2(function find(fn,list){var idx=-1;var len=list.length;while(++idx<len){if(fn(list[idx])){return list[idx]}}});R.findIndex=curry2(function _findIndex(fn,list){var idx=-1;var len=list.length;while(++idx<len){if(fn(list[idx])){return idx}}return-1});R.findLast=curry2(function _findLast(fn,list){var idx=list.length;while(idx--){if(fn(list[idx])){return list[idx]}}});R.findLastIndex=curry2(function _findLastIndex(fn,list){var idx=list.length;while(idx--){if(fn(list[idx])){return idx}}return-1});function every(fn,list){var idx=-1;while(++idx<list.length){if(!fn(list[idx])){return false}}return true}R.every=curry2(every);function some(fn,list){var idx=-1;while(++idx<list.length){if(fn(list[idx])){return true}}return false}R.some=curry2(some);var indexOf=function _indexOf(list,item,from){var idx=0,length=list.length;if(typeof from=="number"){idx=from<0?Math.max(0,length+from):from}for(;idx<length;idx++){if(list[idx]===item){return idx}}return-1};var lastIndexOf=function _lastIndexOf(list,item,from){var idx=list.length;if(typeof from=="number"){idx=from<0?idx+from+1:Math.min(idx,from+1)}while(--idx>=0){if(list[idx]===item){return idx}}return-1};R.indexOf=curry2(function _indexOf(target,list){return indexOf(list,target)});R.indexOf.from=curry3(function indexOfFrom(target,fromIdx,list){return indexOf(list,target,fromIdx)});R.lastIndexOf=curry2(function _lastIndexOf(target,list){return lastIndexOf(list,target)});R.lastIndexOf.from=curry3(function lastIndexOfFrom(target,fromIdx,list){return lastIndexOf(list,target,fromIdx)});function contains(a,list){return indexOf(list,a)>-1}R.contains=curry2(contains);function containsWith(pred,x,list){var idx=-1,len=list.length;while(++idx<len){if(pred(x,list[idx])){return true}}return false}R.containsWith=curry3(containsWith);var uniq=R.uniq=function uniq(list){var idx=-1,len=list.length;var result=[],item;while(++idx<len){item=list[idx];if(!contains(item,result)){result.push(item)}}return result};R.isSet=function _isSet(list){var len=list.length;var idx=-1;while(++idx<len){if(indexOf(list,list[idx],idx+1)>=0){return false}}return true};var uniqWith=R.uniqWith=curry2(function _uniqWith(pred,list){var idx=-1,len=list.length;var result=[],item;while(++idx<len){item=list[idx];if(!containsWith(pred,item,result)){result.push(item)}}return result});var pluck=R.pluck=curry2(function _pluck(p,list){return map(prop(p),list)});var makeFlat=function _makeFlat(recursive){return function __flatt(list){var value,result=[],idx=-1,j,ilen=list.length,jlen;while(++idx<ilen){if(R.isArrayLike(list[idx])){value=recursive?__flatt(list[idx]):list[idx];j=-1;jlen=value.length;while(++j<jlen){result.push(value[j])}}else{result.push(list[idx])}}return result}};R.flatten=makeFlat(true);var unnest=R.unnest=makeFlat(false);R.zipWith=curry3(function _zipWith(fn,a,b){var rv=[],idx=-1,len=Math.min(a.length,b.length);while(++idx<len){rv[idx]=fn(a[idx],b[idx])}return rv});R.zip=curry2(function _zip(a,b){var rv=[];var idx=-1;var len=Math.min(a.length,b.length);while(++idx<len){rv[idx]=[a[idx],b[idx]]}return rv});R.zipObj=curry2(function _zipObj(keys,values){var idx=-1,len=keys.length,out={};while(++idx<len){out[keys[idx]]=values[idx]}return out});R.fromPairs=function _fromPairs(pairs){var idx=-1,len=pairs.length,out={};while(++idx<len){if(isArray(pairs[idx])&&pairs[idx].length){out[pairs[idx][0]]=pairs[idx][1]}}return out};R.xprodWith=curry3(function _xprodWith(fn,a,b){if(isEmpty(a)||isEmpty(b)){return[]}var idx=-1,ilen=a.length,j,jlen=b.length,result=[];while(++idx<ilen){j=-1;while(++j<jlen){result.push(fn(a[idx],b[j]))}}return result});R.xprod=curry2(function _xprod(a,b){if(isEmpty(a)||isEmpty(b)){return[]}var idx=-1;var ilen=a.length;var j;var jlen=b.length;var result=[];while(++idx<ilen){j=-1;while(++j<jlen){result.push([a[idx],b[j]])}}return result});R.reverse=function _reverse(list){return clone(list||[]).reverse()};R.range=curry2(function _range(from,to){if(from>=to){return[]}var idx=0,result=new Array(Math.floor(to)-Math.ceil(from));for(;from<to;idx++,from++){result[idx]=from}return result});R.join=invoker("join",Array.prototype);R.slice=invoker("slice",Array.prototype);R.slice.from=curry2(function(a,xs){return xs.slice(a,xs.length)});R.remove=curry3(function _remove(start,count,list){return concat(_slice(list,0,Math.min(start,list.length)),_slice(list,Math.min(list.length,start+count)))});R.insert=curry3(function _insert(idx,elt,list){idx=idx<list.length&&idx>=0?idx:list.length;return concat(append(elt,_slice(list,0,idx)),_slice(list,idx))});R.insert.all=curry3(function _insertAll(idx,elts,list){idx=idx<list.length&&idx>=0?idx:list.length;return concat(concat(_slice(list,0,idx),elts),_slice(list,idx))});var comparator=R.comparator=function _comparator(pred){return function(a,b){return pred(a,b)?-1:pred(b,a)?1:0}};R.sort=curry2(function sort(comparator,list){return clone(list).sort(comparator)});R.groupBy=curry2(function _groupBy(fn,list){return foldl(function(acc,elt){var key=fn(elt);acc[key]=append(elt,acc[key]||(acc[key]=[]));return acc},{},list)});R.partition=curry2(function _partition(pred,list){return foldl(function(acc,elt){acc[pred(elt)?0:1].push(elt);return acc},[[],[]],list)});R.tap=curry2(function _tap(x,fn){if(typeof fn==="function"){fn(x)}return x});R.eq=curry2(function _eq(a,b){return a===b});var prop=R.prop=function prop(p,obj){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return function _prop(obj){return obj[p]}}return obj[p]};R.get=R.prop;R.props=flip(R.prop);var hasOwnProperty=Object.prototype.hasOwnProperty;R.propOrDefault=curry3(function _propOrDefault(p,val,obj){return hasOwnProperty.call(obj,p)?obj[p]:val});R.func=function _func(funcName,obj){switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return function(obj){return obj[funcName].apply(obj,_slice(arguments,1))};default:return obj[funcName].apply(obj,_slice(arguments,2))}};var always=R.always=function _always(val){return function(){return val}};var nativeKeys=Object.keys;var keys=R.keys=function(){var hasEnumBug=!{toString:null}.propertyIsEnumerable("toString");var nonEnumerableProps=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];return function _keys(obj){if(!R.is(Object,obj)){return[]}if(nativeKeys){return nativeKeys(Object(obj))}var prop,ks=[],nIdx;for(prop in obj){if(hasOwnProperty.call(obj,prop)){ks.push(prop)}}if(hasEnumBug){nIdx=nonEnumerableProps.length;while(nIdx--){prop=nonEnumerableProps[nIdx];if(hasOwnProperty.call(obj,prop)&&!R.contains(prop,ks)){ks.push(prop)}}}return ks}}();R.keysIn=function _keysIn(obj){var prop,ks=[];for(prop in obj){ks.push(prop)}return ks};var pairWith=function(fn){return function(obj){return R.map(function(key){return[key,obj[key]]},fn(obj))}};R.toPairs=pairWith(R.keys);R.toPairsIn=pairWith(R.keysIn);R.values=function _values(obj){var props=keys(obj),length=props.length,vals=new Array(length);for(var idx=0;idx<length;idx++){vals[idx]=obj[props[idx]]}return vals};R.valuesIn=function _valuesIn(obj){var prop,vs=[];for(prop in obj){vs.push(obj[prop])}return vs};function pickWith(test,obj){var copy={},props=keys(obj),prop,val;for(var idx=0,len=props.length;idx<len;idx++){prop=props[idx];val=obj[prop];if(test(val,prop,obj)){copy[prop]=val}}return copy}R.pick=curry2(function pick(names,obj){return pickWith(function(val,key){return contains(key,names)},obj)});R.omit=curry2(function omit(names,obj){return pickWith(function(val,key){return!contains(key,names)},obj)});R.pickWith=curry2(pickWith);var pickAll=function _pickAll(names,obj){var copy={};forEach(function(name){copy[name]=obj[name]},names);return copy};R.pickAll=curry2(pickAll);function extend(destination,other){var props=keys(other),idx=-1,length=props.length;while(++idx<length){destination[props[idx]]=other[props[idx]]}return destination}R.mixin=curry2(function _mixin(a,b){return extend(extend({},a),b)});R.cloneObj=function(obj){return extend({},obj)};R.eqProps=curry3(function eqProps(prop,obj1,obj2){return obj1[prop]===obj2[prop]});function satisfiesSpec(spec,parsedSpec,testObj){if(spec===testObj){return true}if(testObj==null){return false}parsedSpec.fn=parsedSpec.fn||[];parsedSpec.obj=parsedSpec.obj||[];var key,val,idx=-1,fnLen=parsedSpec.fn.length,j=-1,objLen=parsedSpec.obj.length;while(++idx<fnLen){key=parsedSpec.fn[idx];val=spec[key];if(!(key in testObj)){return false}if(!val(testObj[key],testObj)){return false}}while(++j<objLen){key=parsedSpec.obj[j];if(spec[key]!==testObj[key]){return false}}return true}R.where=function where(spec,testObj){var parsedSpec=R.groupBy(function(key){return typeof spec[key]==="function"?"fn":"obj"},keys(spec));switch(arguments.length){case 0:throw NO_ARGS_EXCEPTION;case 1:return function(testObj){return satisfiesSpec(spec,parsedSpec,testObj)}}return satisfiesSpec(spec,parsedSpec,testObj)};R.installTo=function(obj){return extend(obj,R)};R.is=curry2(function is(ctor,val){return val!=null&&val.constructor===ctor||val instanceof ctor});R.alwaysZero=always(0);R.alwaysFalse=always(false);R.alwaysTrue=always(true);R.and=curry2(function and(f,g){return function _and(){return!!(f.apply(this,arguments)&&g.apply(this,arguments))}});R.or=curry2(function or(f,g){return function _or(){return!!(f.apply(this,arguments)||g.apply(this,arguments))}});var not=R.not=function _not(f){return function(){return!f.apply(this,arguments)}};var predicateWrap=function _predicateWrap(predPicker){return function(preds){var predIterator=function(){var args=arguments;return predPicker(function(predicate){return predicate.apply(null,args)},preds)};return arguments.length>1?predIterator.apply(null,_slice(arguments,1)):arity(max(pluck("length",preds)),predIterator)}};R.allPredicates=predicateWrap(every);R.anyPredicates=predicateWrap(some);var add=R.add=curry2(function _add(a,b){return a+b});var multiply=R.multiply=curry2(function _multiply(a,b){return a*b});R.subtract=op(function _subtract(a,b){return a-b});R.divide=op(function _divide(a,b){return a/b});R.modulo=op(function _modulo(a,b){return a%b});var isInteger=Number.isInteger||function isInteger(n){return n<<0===n};R.mathMod=op(function _mathMod(m,p){if(!isInteger(m)){return NaN}if(!isInteger(p)||p<1){return NaN}return(m%p+p)%p});R.sum=foldl(add,0);R.product=foldl(multiply,1);R.lt=op(function _lt(a,b){return a<b});R.lte=op(function _lte(a,b){return a<=b});R.gt=op(function _gt(a,b){return a>b});R.gte=op(function _gte(a,b){return a>=b});var max=R.max=function _max(list){return foldl(binary(Math.max),-Infinity,list)};R.maxWith=curry2(function _maxWith(keyFn,list){if(!(list&&list.length>0)){return}var idx=0,winner=list[idx],max=keyFn(winner),testKey;while(++idx<list.length){testKey=keyFn(list[idx]);if(testKey>max){max=testKey;winner=list[idx]}}return winner});R.min=function _min(list){return foldl(binary(Math.min),Infinity,list)};R.minWith=curry2(function _minWith(keyFn,list){if(!(list&&list.length>0)){return}var idx=0,winner=list[idx],min=keyFn(list[idx]),testKey;while(++idx<list.length){testKey=keyFn(list[idx]);if(testKey<min){min=testKey;winner=list[idx]}}return winner});var substring=R.substring=invoker("substring",String.prototype);R.substringFrom=flip(substring)(void 0);R.substringTo=substring(0);R.charAt=invoker("charAt",String.prototype);R.charCodeAt=invoker("charCodeAt",String.prototype);R.match=invoker("match",String.prototype);R.strIndexOf=curry2(function _strIndexOf(c,str){return str.indexOf(c)});R.strLastIndexOf=curry2(function(c,str){return str.lastIndexOf(c)});R.toUpperCase=invoker("toUpperCase",String.prototype);R.toLowerCase=invoker("toLowerCase",String.prototype);R.split=invoker("split",String.prototype,1);function path(paths,obj){var idx=-1,length=paths.length,val;if(obj==null){return}val=obj;while(val!=null&&++idx<length){val=val[paths[idx]]}return val}R.pathOn=curry3(function pathOn(sep,str,obj){return path(str.split(sep),obj)});R.path=R.pathOn(".");R.project=useWith(map,R.pickAll,identity);R.propEq=curry3(function propEq(name,val,obj){return obj[name]===val});R.union=compose(uniq,R.concat);R.unionWith=curry3(function _unionWith(pred,list1,list2){return uniqWith(pred,concat(list1,list2))});R.difference=curry2(function _difference(first,second){return uniq(reject(flip(contains)(second),first))});R.differenceWith=curry3(function differenceWith(pred,first,second){return uniqWith(pred)(reject(flip(R.containsWith(pred))(second),first))});R.intersection=curry2(function intersection(list1,list2){return uniq(filter(flip(contains)(list1),list2))});R.intersectionWith=curry3(function intersectionWith(pred,list1,list2){var results=[],idx=-1;while(++idx<list1.length){if(containsWith(pred,list1[idx],list2)){results[results.length]=list1[idx]}}return uniqWith(pred,results)});function keyValue(fn,list){return map(function(item){return{key:fn(item),val:item}},list)}R.sortBy=curry2(function sortBy(fn,list){return pluck("val",keyValue(fn,list).sort(comparator(function(a,b){return a.key<b.key})))});R.countBy=curry2(function countBy(fn,list){return foldl(function(counts,obj){counts[obj.key]=(counts[obj.key]||0)+1;return counts},{},keyValue(fn,list))});var functionsWith=function(fn){return function(obj){return R.filter(function(key){return typeof obj[key]==="function"},fn(obj))}};R.functions=functionsWith(R.keys);R.functionsIn=functionsWith(R.keysIn);return R})},{}]},{},[]);var R=require("ramda").installTo(this);var a={};var b={y:a};var c={z:b};a.x=c;var refFrom=[];var refTo=[];var deepCopy=function(obj){if(is(Object,obj)){return copyObj(obj)}else{return obj}console.log("end",refTo)};var copyObj=function(obj){for(var key in obj){console.log(key);if(is(Object,obj[key])){var i=findIndex(function(x){return x===obj[key]},refFrom);if(i!==-1){console.log("stop",refFrom);return refTo[i]}else{refFrom.push(obj[key]);var r=deepCopy(obj[key]);refTo.push(r);console.log("returned: ",r);return r}}else{return obj}}};var z=deepCopy({a:{b:{c:1}}});console.log("result",z);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"ramda": "0.5.0"
}
}
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; }
body, html { height: 100%; width: 100%; }</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment