Last active
August 29, 2015 14:16
-
-
Save st44100/355a73d2b1c80a9b40a4 to your computer and use it in GitHub Desktop.
Array Uniq in coffee script JS Bin// source http://jsbin.com/xiwimo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var cls, curCls, i, key, nodeA, nodeB, res, value, _i, _ref; | |
nodeA = { | |
className: 'txt-a txt-b bold center txt-a' | |
}; | |
cls = 'add-cls'; | |
curCls = nodeA.className.split(' '); | |
curCls.push(cls); | |
nodeA.className = _.uniq(curCls).join(' '); | |
console.log(nodeA); | |
nodeB = { | |
className: 'txt-a txt-b bold center txt-a' | |
}; | |
cls = 'add-cls'; | |
curCls = nodeB.className.split(' '); | |
curCls.push(cls); | |
res = {}; | |
for (i = _i = 0, _ref = curCls.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { | |
res[curCls[i]] = curCls[i]; | |
} | |
curCls = (function() { | |
var _results; | |
_results = []; | |
for (key in res) { | |
value = res[key]; | |
_results.push(value); | |
} | |
return _results; | |
})(); | |
nodeB.className = curCls.join(' '); | |
console.log(nodeA, nodeB, nodeA.className === nodeB.className); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">nodeA = | |
className: 'txt-a txt-b bold center txt-a' | |
cls = 'add-cls' | |
curCls = nodeA.className.split(' ') | |
curCls.push(cls) | |
nodeA.className = _.uniq(curCls).join(' ') | |
console.log nodeA | |
nodeB = | |
className: 'txt-a txt-b bold center txt-a' | |
cls = 'add-cls' | |
curCls = nodeB.className.split(' ') | |
curCls.push(cls) | |
res = {} | |
res[curCls[i]] = curCls[i] for i in [0...curCls.length] | |
curCls = for key, value of res then value | |
nodeB.className = curCls.join(' ') | |
console.log nodeA, nodeB , nodeA.className is nodeB.className | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nodeA = | |
className: 'txt-a txt-b bold center txt-a' | |
cls = 'add-cls' | |
curCls = nodeA.className.split(' ') | |
curCls.push(cls) | |
nodeA.className = _.uniq(curCls).join(' ') | |
console.log nodeA | |
nodeB = | |
className: 'txt-a txt-b bold center txt-a' | |
cls = 'add-cls' | |
curCls = nodeB.className.split(' ') | |
curCls.push(cls) | |
res = {} | |
res[curCls[i]] = curCls[i] for i in [0...curCls.length] | |
curCls = for key, value of res then value | |
nodeB.className = curCls.join(' ') | |
console.log nodeA, nodeB , nodeA.className is nodeB.className |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cls, curCls, i, key, nodeA, nodeB, res, value, _i, _ref; | |
nodeA = { | |
className: 'txt-a txt-b bold center txt-a' | |
}; | |
cls = 'add-cls'; | |
curCls = nodeA.className.split(' '); | |
curCls.push(cls); | |
nodeA.className = _.uniq(curCls).join(' '); | |
console.log(nodeA); | |
nodeB = { | |
className: 'txt-a txt-b bold center txt-a' | |
}; | |
cls = 'add-cls'; | |
curCls = nodeB.className.split(' '); | |
curCls.push(cls); | |
res = {}; | |
for (i = _i = 0, _ref = curCls.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { | |
res[curCls[i]] = curCls[i]; | |
} | |
curCls = (function() { | |
var _results; | |
_results = []; | |
for (key in res) { | |
value = res[key]; | |
_results.push(value); | |
} | |
return _results; | |
})(); | |
nodeB.className = curCls.join(' '); | |
console.log(nodeA, nodeB, nodeA.className === nodeB.className); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment