Namespace Pot.Struct
Defined in: <pot.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Struct.
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
Pot.Struct.bind(func, self)
Creates a new function with specified context and arguments.
|
| <static> |
Pot.Struct.clearObject(o)
Clears the object that is any types.
|
| <static> |
Pot.Struct.clone(o)
Clone an object.
|
| <static> |
Pot.Struct.contains(object, subject)
Whether the object contains the given subject.
|
| <static> |
Pot.Struct.count(o)
Count the object items then return total number.
|
| <static> |
Pot.Struct.equals(object, subject, (func))
Compares two objects for equality.
|
| <static> |
Pot.Struct.explode(string, (delimiter), (separator))
Separate a string by specified delimiter and separator,
then returns a converted object.
|
| <static> |
Pot.Struct.fill(defaults, value, count)
Fill the first argument value with in the specific value.
|
| <static> |
Pot.Struct.first(o, keyOnly)
Get the first orders value in object.
|
| <static> |
Pot.Struct.firstKey(o)
Get the first orders key in object.
|
| <static> |
Pot.Struct.flip(o)
Flips the object.
|
| <static> |
Pot.Struct.glue(args)
Joins the all arguments to a string.
|
| <static> |
Pot.Struct.implode(object, (delimiter), (separator), (tail))
Return a string that is joined by the object keys and values.
|
| <static> |
Pot.Struct.invoke(object, method, (args))
Call the function with unknown number arguments.
|
| <static> |
Pot.Struct.keys(o)
Collect the object key names like ES5's Object.keys().
|
| <static> |
Pot.Struct.last(o, keyOnly)
Get the last orders value in object.
|
| <static> |
Pot.Struct.lastKey(o)
Get the last orders key in object.
|
| <static> |
Pot.Struct.pairs()
Creates an object from a key-value pairs.
|
| <static> |
Pot.Struct.partial(func)
Create a new function like Function.bind,
except that a "this" is not required.
|
| <static> |
Pot.Struct.remove(object, subject, (loose))
Return the copy object that was removed a subject value.
|
| <static> |
Pot.Struct.removeAll(object, subject, (loose))
Return the copy object that was removed all subject value.
|
| <static> |
Pot.Struct.removeAt(object, index, (length))
Return the copy object that was removed a subject value.
|
| <static> |
Pot.Struct.reverse(o)
Reverse the object.
|
| <static> |
Pot.Struct.shuffle(array)
Shuffle an object and returns it.
|
| <static> |
Pot.Struct.tuple(items, (callback), (defaultType))
Revert to an object from items() format array.
|
| <static> |
Pot.Struct.unzip(zipped, (callback))
Revert to an object from zip() format array.
|
| <static> |
Pot.Struct.values(o)
Collect the object values.
|
Method Detail
<static>
{Function}
Pot.Struct.bind(func, self)
Creates a new function with specified context and arguments.
var Hoge = function() {
this.msg = 'Hello Hoge!';
};
Hoge.prototype.sayHoge = function() {
debug(this.msg);
};
var hoge = new Hoge();
//
// direct
setTimeout(hoge.sayHoge, 1000); // undefined
//
// bind
setTimeout(bind(hoge.sayHoge, hoge), 1000); // Hello Hoge!
//
// use arguments
Hoge.prototype.sayHoges = function(msg) {
debug(this.msg + msg);
};
//
// direct
setTimeout(hoge.sayHoges, 1000); // NaN
//
// bind
setTimeout(bind(hoge.sayHoges, hoge, 'Hi!'), 1000); // Hello Hoge!Hi!
- Parameters:
- {Function} func
- A function to partially apply.
- {*} self
- Specifies the object as "this". If the value is unspecified, it will default to the global object.
- {...*} (...)
- Additional arguments that are partially applied to the function.
- Returns:
- {Function} A new function that will invoked with original context and partially-applied arguments.
<static>
{Function}
Pot.Struct.clearObject(o)
Clears the object that is any types.
var obj = {foo: 1, bar: 2, baz: 3};
clearObject(obj);
debug(obj);
// @results obj = {}
var arr = [1, 2, 3, 4, 5];
clearObject(arr);
debug(arr);
// @results arr = []
- Parameters:
- {*} o
- A target object.
- Returns:
- {*} Return argument `o`.
<static>
{Function}
Pot.Struct.clone(o)
Clone an object.
var obj1 = {key: 'value'};
var obj2 = clone(obj1);
obj2.hoge = 'fuga';
debug(obj1.hoge); // undefined
debug(obj2.hoge); // 'fuga'
- Parameters:
- {*} o
- Target object.
- Returns:
- {*} Cloned object.
<static>
{Function}
Pot.Struct.contains(object, subject)
Whether the object contains the given subject.
var obj = {foo: 10, bar: 20, baz: 30};
debug(contains(obj, 20)); // true
debug(contains(obj, 50)); // false
var arr = [10, 20, 30, 'foo', 'bar'];
debug(contains(arr, 20)); // true
debug(contains(arr, 75)); // false
debug(contains(arr, 'foo')); // true
debug(contains(arr, 'FOO')); // false
var str = 'foobarbaz';
debug(contains(str, 'A')); // false
debug(contains(str, 'foo')); // true
debug(contains(str, '123')); // false
var num = 12345;
debug(contains(num, 1)); // true
debug(contains(num, 45)); // true
debug(contains(num, 7)); // false
- Parameters:
- {*} object
- The object to test for the presence of the element.
- {*} subject
- The object for which to test.
- Returns:
- {Boolean} true if subject is present.
<static>
{Function}
Pot.Struct.count(o)
Count the object items then return total number.
debug(count({a: 1, b: 2, c: 3})); // 3
debug(count({})); // 0
debug(count([1, 2, 3, 4, 5])); // 5
debug(count([])); // 0
debug(count(new Object('foo', 'bar', 'baz'))); // 3
debug(count(new Array(100))); // 100
debug(count(null)); // 0
debug(count((void 0))); // 0
debug(count('hoge')); // 4
debug(count('')); // 0
debug(count(new String('hoge'))); // 4
debug(count(100)); // 100
debug(count(0)); // 0
debug(count(-1)); // 1
debug(count((function() {}))); // 0
var f = function() {};
f.foo = 1;
f.bar = 2;
debug(count(f)); // 2
- Parameters:
- {Object|*} o
- The target object.
- Returns:
- {Number} The total count.
<static>
{Function}
Pot.Struct.equals(object, subject, (func))
Compares two objects for equality.
If two objects have same length and same scalar value then
will return true. Otherwise will return false.
var obj1 = {foo: 10, bar: 20, baz: 30};
var obj2 = {foo: 10, bar: 20, baz: 30};
var obj3 = {a: 'hoge', b: 'fuga'};
debug(equals(obj1, obj2)); // true
debug(equals(obj1, obj3)); // false
var obj4 = {};
var obj5 = {};
debug(equals(obj4, obj5)); // true
var arr1 = [1, 2, 3];
var arr2 = [1, 2, 3];
var arr3 = [1, 2, 10];
debug(equals(arr1, arr2)); // true
debug(equals(arr1, arr3)); // false
var arr4 = [];
var arr5 = [];
debug(equals(arr4, arr5)); // true
var cmp = function(a, b) {
return a == b ||
String(a).toLowerCase() == String(b).toLowerCase();
};
var arr6 = [1, 2, 'foo', 'bar'];
var arr7 = ['1', 2, 'FOO', 'baR'];
debug(equals(arr6, arr7, cmp)); // true
var func1 = (function() {});
var func2 = (function() {});
var func3 = (function() { return this; });
debug(equals(func1, func2)); // true
debug(equals(func1, func3)); // false
var date1 = new Date(); var date2 = new Date(date1.getTime()); var date3 = new Date(date1.getTime() + 100); debug(equals(date1, date2)); // true debug(equals(date1, date3)); // false
var str1 = 'foobarbaz'; var str2 = 'foobarbaz'; var str3 = 'hoge'; debug(equals(str1, str2)); // true debug(equals(str1, str3)); // false
var num1 = 12345; var num2 = 12345; var num3 = 12345.455512; var num4 = 12345.443556; var num5 = 12345.443556999; debug(equals(num1, num2)); // true debug(equals(num1, num3)); // false debug(equals(num3, num4)); // false debug(equals(num4, num5)); // true
- Parameters:
- {Array|Object|*} object
- The first object to compare.
- {Array|Object|*} subject
- The second object to compare.
- {Function} (func)
- (Optional) The comparison function. e.g. function(a, b) { return a == b; } Should take 2 arguments to compare, and return true if the arguments are equal. Defaults to which compares the elements using the built-in '===' operator.
- Returns:
- {Boolean} Whether the two objects are equal.
<static>
{Function}
Pot.Struct.explode(string, (delimiter), (separator))
Separate a string by specified delimiter and separator,
then returns a converted object.
This function works like the opposite "implode".
var string = 'color:blue;margin:5px;';
var result = explode(string, ':', ';');
debug(result);
// @results {color: 'blue', margin: '5px'}
var string = 'foo=1&bar=2&baz=3';
var result = explode(string, {delimiter: '=', separator: '&'});
debug(result);
// @results {foo: '1', bar: '2', baz: '3'}
var string = 'A : 1, B:2, C: 3;';
var result = explode(string, {
delimiter : /(?:\s*:\s*)/,
separator : /(?:\s*[,;]\s*)/
});
debug(result);
// @results {A: '1', B: '2', C: '3'}
- Parameters:
- {String} string
- The subject string.
- {String|RegExp} (delimiter)
- The split character of each property name and value. (default = ':').
- {String|RegExp} (separator)
- The character string that will be split by the following property and previous property. (default = ',').
- Returns:
- {Object} The result object that separated from a string.
- See:
- Pot.Struct.implode
<static>
{Function}
Pot.Struct.fill(defaults, value, count)
Fill the first argument value with in the specific value.
The available first argument types are Array and String, and Object.
debug(fill([1, 2], 3, 5));
// @results [1, 2, 3, 3, 3, 3, 3]
debug(fill([], null, 3));
// @results [null, null, null]
debug(fill('foo', 'o', 10));
// @results 'foooooooooooo'
debug(fill('', 'hoge', 5));
// @results 'hogehogehogehogehoge'
debug(fill({}, 2, 5));
// @results {'0': 2, '1': 2, '2': 2, '3': 2, '4': 2}
debug(fill({a: 1, b: 2, c: 3}, null));
// @results {a: null, b: null, c: null}
debug(fill(100, 5, 10));
// @results 5555555555100
- Parameters:
- {Array|String|Object|Number|*} defaults
- The default value. This object value does not replace. use returned value.
- {*} value
- The value to fill the object.
- {Number} count
- The number of times to fill the object.
- Returns:
- {Array|String|Object|Number|*} The result of filled.
<static>
{Function}
Pot.Struct.first(o, keyOnly)
Get the first orders value in object.
debug(first({a: 1, b: 2, c: 3})); // 1
debug(first({})); // undefined
debug(first([1, 2, 3, 4, 5])); // 1
debug(first([])); // undefined
debug(first({a: 'foo', b: 'bar'})); // 'foo'
debug(first(new Array(100))); // undefined
debug(first(null)); // undefined
debug(first((void 0))); // undefined
debug(first('hoge')); // 'h'
debug(first('')); // ''
debug(first(new String('hoge'))); // 'h'
debug(first(123)); // 3
debug(first(0)); // 0
debug(first(-123)); // 3
- Parameters:
- {Object|Array|*} o
- The target object.
- keyOnly
- Returns:
- {*} The first value in object.
<static>
{Function}
Pot.Struct.firstKey(o)
Get the first orders key in object.
debug(firstKey({a: 1, b: 2, c: 3})); // 'a'
debug(firstKey({})); // undefined
debug(firstKey([1, 2, 3, 4, 5])); // 0
debug(firstKey([])); // undefined
debug(firstKey({a: 'foo', b: 'bar'})); // 'a'
debug(firstKey(new Array(100))); // undefined
debug(firstKey(null)); // undefined
debug(firstKey((void 0))); // undefined
debug(firstKey('hoge')); // 0
debug(firstKey('')); // null
debug(firstKey(new String('hoge'))); // 0
debug(firstKey(123)); // 0
debug(firstKey(0)); // 0
debug(firstKey(-123)); // 0
- Parameters:
- {Object|Array|*} o
- The target object.
- Returns:
- {*} The first key in object.
<static>
{Function}
Pot.Struct.flip(o)
Flips the object.
debug(flip({foo: 'A', bar: 'B', baz: 'C'}));
// @results {A: 'foo', B: 'bar', C: 'baz'}
- Parameters:
- {Object|Array|*} o
- A target object.
- Returns:
- {Object|*} The result object.
<static>
{Function}
Pot.Struct.glue(args)
Joins the all arguments to a string.
debug(glue([1, 2, 3, 4, 5]));
// @results '12345'
debug(glue('foo', 'bar', 'baz'));
// @results 'foobarbaz'
debug(glue(1, [2, 3, ['foo']], ['bar', 'baz']));
// @results '123foobarbaz'
- Parameters:
- {Array|...*} args
- The target items.
- Returns:
- {String} The joined string from array.
<static>
{Function}
Pot.Struct.implode(object, (delimiter), (separator), (tail))
Return a string that is joined by the object keys and values.
Arguments can passed in any order.
(The first will be the `delimiter` as a string).
If the `tail` is given as string
then will be append the `tail` itself to string.
debug(implode({color: 'blue', margin: '5px'}, ':', ';', true));
// @results 'color:blue;margin:5px;'
//
// Arguments can passed in any order.
// (The first will be the `delimiter` as a string).
//
debug(implode('+', {a: 1, b: 2, c: 3}, '*'));
// @results 'a+1*b+2*c+3'
//
// If the `tail` is given as string
// then will be append the `tail` itself to string.
//
debug(implode('>>', {a: 1, b: 2, c: 3}, '^', '==?'));
// @results 'a>>1^b>>2^c>>3==?'
- Parameters:
- {Object} object
- The target object.
- {String} (delimiter)
- The combining character of each property name and value. (default = ':').
- {String} (separator)
- The character string that will be combined by the following property and previous property. (default = ',').
- {Boolean} (tail)
- If given "true" then will put `separator` to the end of the string.
- Returns:
- {String} The combined string.
<static>
{Function}
Pot.Struct.invoke(object, method, (args))
Call the function with unknown number arguments.
That is for cases where JavaScript sucks
built-in function like alert() on IE or other-browser when
calls the Function.apply.
debug(invoke(window, 'alert', 100));
debug(invoke(document, 'getElementById', 'container'));
debug(invoke(window, 'setTimeout', function() { debug(1); }, 2000));
- Parameters:
- {Object} object
- The context object (e.g. window)
- {String} method
- The callable function name.
- {Array|...*} (args)
- The function arguments.
- Returns:
- {*} The result of the called function.
<static>
{Function}
Pot.Struct.keys(o)
Collect the object key names like ES5's Object.keys().
var obj = {foo: 1, bar: 2, baz: 3};
debug(keys(obj));
// @results ['foo', 'bar', 'baz']
var array = [10, 20, 30, 40, 50];
debug(keys(array));
// @results [0, 1, 2, 3, 4]
delete array[2];
debug(keys(array));
// @results [0, 1, 3, 4]
- Parameters:
- {Object} o
- The target object.
- Returns:
- {Array} The collected key names as an array.
<static>
{Function}
Pot.Struct.last(o, keyOnly)
Get the last orders value in object.
debug(last({a: 1, b: 2, c: 3})); // 3
debug(last({})); // undefined
debug(last([1, 2, 3, 4, 5])); // 5
debug(last([])); // undefined
debug(last({a: 'foo', b: 'bar'})); // 'bar'
debug(last(new Array(100))); // undefined
debug(last(null)); // undefined
debug(last((void 0))); // undefined
debug(last('hoge')); // 'e'
debug(last('')); // ''
debug(last(new String('hoge'))); // 'e'
debug(last(123)); // 1
debug(last(0)); // 0
debug(last(-123)); // 1
- Parameters:
- {Object|Array|*} o
- The target object.
- keyOnly
- Returns:
- {*} The last value in object.
<static>
{Function}
Pot.Struct.lastKey(o)
Get the last orders key in object.
debug(lastKey({a: 1, b: 2, c: 3})); // 'c'
debug(lastKey({})); // undefined
debug(lastKey([1, 2, 3, 4, 5])); // 4
debug(lastKey([])); // undefined
debug(lastKey({a: 'foo', b: 'bar'})); // 'b'
debug(lastKey(new Array(100))); // undefined
debug(lastKey(null)); // undefined
debug(lastKey((void 0))); // undefined
debug(lastKey('hoge')); // 3
debug(lastKey('')); // null
debug(lastKey(new String('hoge'))); // 3
debug(lastKey(123)); // 2
debug(lastKey(0)); // 0
debug(lastKey(-123)); // 2
- Parameters:
- {Object|Array|*} o
- The target object.
- Returns:
- {*} The last key in object.
<static>
{Function}
Pot.Struct.pairs()
Creates an object from a key-value pairs.
debug(pairs('key', 'value'));
// @results {key : 'value'}
debug(pairs('key1', 'value1', 'key2', 'value2'));
// @results {key1: 'value1', key2: 'value2'}
debug(pairs('key'));
// @results {key: undefined}
debug(pairs(['key', 'value']));
// @results {key: 'value'}
debug(pairs('key1', 1, ['key2', 2], 'key3', 3));
// @results {key1: 1, key2: 2, key3: 3}
debug(pairs(['a', 1, ['b', 2, [{c: 3}, 'd', 4]]]));
// @results {a: 1, b: 2, c: 3, d: 4}
- Parameters:
- {String|*} (...)
- The key-value pairs.
- Returns:
- {Object} The created object.
<static>
{Function}
Pot.Struct.partial(func)
Create a new function like Function.bind,
except that a "this" is not required.
That is useful when the target function is already bound.
function add(a, b) {
return a + b;
}
var add2 = partial(add, 2);
var result = add2(5);
debug(result);
// @results 7
- Parameters:
- {Function} func
- A function to partially apply.
- {...*} (...)
- Additional arguments that are partially applied to `func`.
- Returns:
- {Function} A new function that will invoked with partially-applied arguments.
<static>
{Function}
Pot.Struct.remove(object, subject, (loose))
Return the copy object that was removed a subject value.
// String
debug(remove('foo bar baz', 'o')); // 'fo bar baz'
debug(remove('foo bar baz', 'bar')); // 'foo baz'
// Array
debug(remove([1, 2, 3, 4, 5], 2)); // [1, 3, 4, 5]
debug(remove([1, 2, 3, 4, 5], '3')); // [1, 2, 3, 4, 5]
debug(remove([1, 2, 3, 4, 5], '3', true)); // [1, 2, 4, 5]
// Object
debug(remove({A: 1, B: 2, C: 3}, 2)); // {A: 1, C: 3}
debug(remove({A: 1, B: 2, C: 3}, '3')); // {A: 1, B: 2, C: 3}
debug(remove({A: 1, B: 2, C: 3}, '3', true)); // {A: 1, B: 2}
// Number
debug(remove(1234512345, 2)); // 134512345
debug(remove(1234512345, 123)); // 4512345
- Parameters:
- {*} object
- The target value.
- {*} subject
- The subject value.
- {Boolean} (loose)
- Whether to use loose compare operator(==). Default is strict operator(===).
- Returns:
- {*} The removed value.
<static>
{Function}
Pot.Struct.removeAll(object, subject, (loose))
Return the copy object that was removed all subject value.
// String
debug(removeAll('foo bar baz', 'o')); // 'f bar baz'
debug(removeAll('foo bar baz', 'ba')); // 'foo r z'
// Array
debug(removeAll([1, 2, 3, 1, 2], 2)); // [1, 3, 1]
debug(removeAll([1, 2, 3, 1, 2], '2')); // [1, 2, 3, 1, 2]
debug(removeAll([1, 2, 3, 1, 2], '2', true)); // [1, 3, 1]
// Object
debug(removeAll({A: 1, B: 2, C: 2}, 2)); // {A: 1}
debug(removeAll({A: 1, B: 2, C: 2}, '2')); // {A: 1, B: 2, C: 2}
debug(removeAll({A: 1, B: 2, C: 2}, '2', true)); // {A: 1}
// Number
debug(removeAll(1234512345, 2)); // 13451345
debug(removeAll(1234512345, 123)); // 4545
- Parameters:
- {*} object
- The target value.
- {*} subject
- The subject value.
- {Boolean} (loose)
- Whether to use loose compare operator(==). Default is strict operator(===).
- Returns:
- {*} The removed value.
<static>
{Function}
Pot.Struct.removeAt(object, index, (length))
Return the copy object that was removed a subject value.
// String
debug(removeAt('foo bar baz', 2)); // 'fo bar baz'
debug(removeAt('foo bar baz', 2, 5)); // 'fo baz'
debug(removeAt('foo bar baz', 100)); // 'foo bar baz'
// Array
debug(removeAt([1, 2, 3, 4, 5], 2)); // [1, 2, 4, 5]
debug(removeAt([1, 2, 3, 4, 5], 2, 2)); // [1, 2, 5]
debug(removeAt([1, 2, 3, 4, 5], -1, 5)); // [1, 2, 3, 4]
// Object
debug(removeAt({A: 1, B: 2, C: 3}, 2)); // {A: 1, B: 2}
debug(removeAt({A: 1, B: 2, C: 3}, 1, 5)); // {A: 1}
debug(removeAt({A: 1, B: 2, C: 3}, 5)); // {A: 1, B: 2, C: 3}
// Number
debug(removeAt(1234512345, 2)); // 123451245
debug(removeAt(1234512345, 2, 3)); // 1234545
debug(removeAt(-1234512345, 2, 3)); // -1234545
- Parameters:
- {*} object
- The target value.
- {Number} index
- The start index.
- {Number} (length)
- (Optional) The removal length (default=1).
- Returns:
- {*} The removed value.
<static>
{Function}
Pot.Struct.reverse(o)
Reverse the object.
debug(reverse({foo: 1, bar: 2, baz: 3}));
// @results {baz: 3, bar: 2, foo: 1}
debug(reverse([1, 2, 3, 4, 5])); // @results [5, 4, 3, 2, 1]
debug(reverse('123abc'));
// @results 'cba321'
- Parameters:
- {Object|Array|*} o
- A target object.
- Returns:
- {Object|*} The result object.
<static>
{Function}
Pot.Struct.shuffle(array)
Shuffle an object and returns it.
This function keeps the original object intact.
debug(shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9]));
// @results e.g. (uncertain)
// [8, 1, 6, 4, 3, 5, 2, 7, 9]
//
debug(shuffle(['foo', 'bar', 'baz']));
// @results e.g.
// ['bar', 'foo', 'baz']
//
debug(shuffle(12345));
// @results e.g.
// 25143
//
debug(shuffle(-123456789.0839893));
// @results e.g.
// -276195348.9908833
//
debug(shuffle({a: 1, b: 2, c: 3, d: 4, e: 5}));
// @results e.g.
// {c: 3, b: 2, d: 4, e: 5, a: 1}
//
debug(shuffle('abcdef12345'));
// @results e.g.
// 'ae2d135cb4f'
//
- Parameters:
- {Array} array
- A target array.
- Returns:
- {Array} An array of result.
<static>
{Function}
Pot.Struct.tuple(items, (callback), (defaultType))
Revert to an object from items() format array.
var array = [['foo', 1], ['bar', 2], ['baz', 3]];
debug(tuple(array));
// @results {foo: 1, bar: 2, baz: 3}
var array = [['foo', 1, 'bar', 2], {baz: 3}, ['A', 4, 'B']];
debug(tuple(array));
// @results {foo: 1, bar: 2, baz: 3, A: 4, B: (void 0)}
// Callback function usage:
var array = [['A', 1], ['B', 2], ['C', 3]];
var func = function(key, val) {
return ['[' + key + ']', '{' + val + '}'];
};
debug(tuple(array, func));
// @results {'[A]': '{1}', '[B]': '{2}', '[C]': '{3}'}
// Example to specify the type of result:
var array = [['prototype', 1], ['__iterator__', 2], ['__proto__', 3]];
debug(tuple(array, new Pot.Hash()).toJSON());
// @results {"prototype": 1, "__iterator__": 2, "__proto__": 3}
// Example to specify the type of result
// (enables Array, Object, Pot.Hash etc.):
var array = [['A', 1], ['B', 2], ['C', 3]];
var func = function(key, val) {
return '(' + key + ':' + val + ')';
};
debug(tuple(array, func, []));
// @results ['(A:1)', '(B:2)', '(C:3)']
- Parameters:
- {Array} items
- The target object.
- {Function|*} (callback)
- (Optional) Callback function.
- {*} (defaultType)
- (Optional) An object literal to specify the type of result.
- Returns:
- {Object} The collected object.
<static>
{Function}
Pot.Struct.unzip(zipped, (callback))
Revert to an object from zip() format array.
Example:
arguments: [[1, 4],
[2, 5],
[3, 6]]
results: [1, 2, 3],
[4, 5, 6]
Example:
arguments: [[{a: 1}, {d: 4}],
[{b: 2}, {e: 5}],
[{c: 3}, {f: 6}]]
results: {a: 1, b: 2, c: 3},
{d: 4, e: 5, f: 6}
debug(unzip([[1, 4], [2, 5], [3, 6]]));
// @results
// [[1, 2, 3], [4, 5, 6]]
//
debug(unzip([[{a: 1}, {d: 4}], [{b: 2}, {e: 5}], [{c: 3}, {f: 6}]]));
// @results
// [{a:1, b:2, c:3}, {d:4, e:5, f:6}]
//
var callback = function(a, b, c) { return a + b + c; };
debug(unzip([[1, 4], [2, 5], [3, 6]], callback));
// @results
// [6, 15]
//
- Parameters:
- {Array} zipped
- Target array.
- {Function|*} (callback)
- (Optional) Callback function.
- Returns:
- {Array} The collected array object.
- See:
- http://docs.python.org/library/functions.html#zip
- Pot.zip
<static>
{Function}
Pot.Struct.values(o)
Collect the object values.
var obj = {foo: 1, bar: 2, baz: 3};
debug(values(obj));
// @results [1, 2, 3]
var array = ['foo', 'bar', 'baz'];
debug(values(array));
// @results ['foo', 'bar', 'baz'];
delete array[1];
debug(values(array));
// @results ['foo', 'baz']
- Parameters:
- {Object} o
- The target object.
- Returns:
- {Array} The collected values as an array.