Skip to content

Instantly share code, notes, and snippets.

@zuk
Created May 28, 2012 17:15
Show Gist options
  • Select an option

  • Save zuk/2820152 to your computer and use it in GitHub Desktop.

Select an option

Save zuk/2820152 to your computer and use it in GitHub Desktop.
[1, 2, 3]
{1: 'a', 2: 'b', 3: 'c'}
[
{eq: 1, foo: "asdfasdf"},
{eq: 2, foo: "asdfasdfsdfasdf"}
]
a = {
"aaa": {foo: "foobar"},
"bbb": {foo: "alpha"}
}
a["aaa"] == {foo: "foobar"};
a["aaa"]["foo"] == "foobar"
[
1 ---> x
2 ---> y
3 ---> z
]
var a = [1, 2, 3];
var h = {1: 'a', 2: 'b', 3: 'c'};
var c = [[1, 3, 4], [1, 4, 8], [3, 4, 5]]
var c2 = [['a', 'b', 'c'], ['c', 'd', 'd']]
var mapFunc = function (e) {
return [e];
};
var b = _.map(a, mapFunc);
_.each(a, function (el) {
jQuery('#aa').append();
});
b == [2, 4, 6];
b == [[1], [2], [3]];
var b = [];
for (var i = 0; i < a.length; i++) {
for (var j = 0; j < a.le)
b.push(a[i])
}
var h = {1: 'a', 2: 'b', 3: 'c'};
<select>
<option value="soemething">sdfd</option>
</select>
var a2 = _.map(h, function (val, key) {
return "<option value='"+key+"'>"+val+"</option>";
});
a2 = ["<option value='1'>a</option>", "<option value='2'>b</option>"]
a2.join() --> "<option"
a3 = ['a', 'b', 'c']
a3.join("<br />") ---> 'a<br />b<br />c'
var h = {1: 'a', 2: 'b', 3: 'c'};
_.keys(h) ---> [1, 3, 3]
_.values(h) -> ['a', 'b', 'c']
var eqs = [
{eqid: 34, name: "a"},
{eqid: 28, name: "b"},
{eqid: 232, name: "c"}
]
_.find(eqs, function (eq) {
return eq['eqid'] == 28;
}) ---> {eqid: 28, name: 'b'}
var eqs2 = {};
_.each(eqs, function (eq) {
eqs2[eq['eqid']] = {name: eq['name']}
})
var eqs = {
34: {name: "a"},
28: {name: "b"},
232: {name: "c"}
}
eqs[28];
var names = _.map(eqs, function (v, k) { return v.name });
names == ['a', 'b', 'c'];
[{names: 'a'}, {names: 'b'}]
_.each(eqs, function (v, k) {
aisldflskdjf
})
var ids = var names = _.map(eqs, function (v, k) { return k }) == _.keys(eqs);;
ids == [34, 28, 232]
ids =
table = "<table>";
_.keys(eqs) ---> [34, 28, 232]
_.each(_.keys(eqs), function (eqId) {
table += "<tr><td>"+eqs[eqId]+"</td></tr>"
});
var transformed = _.map(collection, function (value, key) { return value });
_.each(collection, function (value, key) { });
var nums = [1, 3, 4, 5, 6, 8, 3]
_.each(nums, function (i) {
if (isAPrimeNumber(i))
laskdf
})
var primes = _.filter(nums, function (n) { return isAPrimeNumber(i); })
---> [1,3,5,3]
_.each(primes, function (n) {})
['a', 'b', 'c', 'c']
_.uniq(collection) ---> ['a', 'b', 'c']
{3: "aaa"} === {3: "aaa"} ---> false
----->
[{3: 'aaa'}, {3: 'aaa'}] _.map(a, function (v) { return JSON.stringify(v)})
[[3, 'aaa'], [3, 'aaa']]
{3: 'aaa'} ---> "{3: 'aaa'}"
JSON.parse("{3: 'aaa'}")
3 === "3" ---> false
3 == "3" ---> true
"3" === "3"
a = [[1, 3, 4], [1, 4, 8], [3, 4, 5]]
_.flatten(a) ---> [1, 3, 4, 1, 4, 8, 3, 4, 5]
_.uniq(_.flatten(a))
a.flatten.uniq
map ---> [a, a, a]
each --->
filter ---> [a, a, a]
find ---> a
uniq ---> [a, a]
flatten ---> [a, a, a]
keys ---> [k, k, k]
values ---> [v, v, v]
_.each(arr, function (el) {
console.log(el);
});
arr = [1, 3, 3]
$('div.foo').toArray() ---> [<div>, <div>, <div>]
$('div.foo').each(function () {
var el = this;
console.log(el)
});
[<input>, <input>, <input>]
var userValues = $('input[type="text"]').map(function () {
return this.value;
return $(this).val();
}).toArray();
---> ['foo', 'bar', 'ccc']
/***************/
var myMongoRecord = {};
$('input[type="text"]').each(function () {
var input = $(this);
myMongoRecord[input.attr('name')] = input.val();
})
myMongoRecord == {
'foo': "something",
'bar': "something else"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment