30,22 → 30,37 |
var jsx = {}; |
} |
|
/* for JSDT only */ |
if (typeof jsx.python == "undefined") |
{ |
/** @namespace */ |
jsx.python = {}; |
} |
|
/** |
* @type jsx.python |
* @memberOf __jsx.python |
* @namespace |
*/ |
jsx.python = { |
jsx.python = (/** @constructor */ function () { |
var _jsx_object = jsx.object; |
var _getKeys = _jsx_object.getKeys; |
var _isArray = _jsx_object.isArray; |
var _isObject = _jsx_object.isObject; |
|
return { |
/** |
* @version |
* @memberOf jsx.python |
*/ |
version: "$Revision$ ($Date$)", |
copyright: "Copyright \xA9 2011-2013", |
author: "Thomas Lahn", |
email: "js@PointedEars.de", |
path: "http://PointedEars.de/scripts/" |
}; |
path: "http://PointedEars.de/scripts/", |
|
/** |
* Returns a reference to an <code>Array</code> instance whose |
* Returns a reference to an <code>Array</code> whose |
* items are the numbers from <var>start</var> inclusive to |
* <var>end</var> exclusive using step width <var>step</var> |
* (may be negative). |
55,7 → 70,7 |
* @param {number} step = 1 |
* @return {Array} |
*/ |
jsx.python.range = function (start, end, step) { |
range: function (start, end, step) { |
var result = []; |
|
if (!step) |
78,7 → 93,7 |
} |
|
return result; |
}; |
}, |
|
/** |
* Returns a reference to an Array instance containing |
87,9 → 102,11 |
* |
* @function |
*/ |
jsx.python.list = (function () { |
var _jsx_object = jsx.object; |
var _isArray = _jsx_object.isArray; |
list: jsx.object.extend(( |
/** |
* @factory |
*/ |
function () { |
var _hasOwnProperty = _jsx_object._hasOwnProperty; |
|
/** |
114,8 → 131,7 |
|
return result; |
}; |
}()); |
|
}()), { |
/** |
* List comprehension. |
* |
127,24 → 143,18 |
* if <var>condition</var> is a <code>true-value</code> or |
* <code>undefined</code>, and no items if it is another |
* false-value). |
*/ |
jsx.python.list.from = (function () { |
var _jsx_object = jsx.object; |
var _getKeys = _jsx_object.getKeys; |
var _isArray = _jsx_object.isArray; |
var _isObject = _jsx_object.isObject; |
var _range = jsx.python.range; |
|
/** |
* |
* @memberOf jsx.python.list |
* @param {Function|any} mapper |
* @param {Object} iterable |
* @param {Function|boolean} condition |
* @return {Array} |
*/ |
return function (mapper, iterable, condition) { |
from: function (mapper, iterable, condition) { |
var result = []; |
|
var iterableIsArray = _isArray(iterable); |
var _range = jsx.python.range; |
if (iterableIsArray) |
{ |
var len = iterable.length; |
192,8 → 202,9 |
} |
|
return result; |
}; |
}()); |
} |
} |
), |
|
/** |
* Returns a reference to an object |
201,7 → 212,7 |
* @param mapping |
* @return {Object} |
*/ |
jsx.python.dict = function (mapping, values) { |
dict: function (mapping, values) { |
var result = {}; |
|
if (typeof mapping == "undefined") |
237,12 → 248,20 |
} |
|
return result; |
}; |
}, |
|
/** |
* Build an unordered collection of unique elements. |
* |
* @type jsx.python.set |
* @function |
*/ |
jsx.python.set = (function () { |
set: ( |
/** |
* @constructor |
* @factory |
*/ |
function () { |
var _jsx = jsx; |
var _jsx_object = _jsx.object; |
var _Map; |
311,9 → 330,11 |
this._elements = result; |
this.length = this._elements.length; |
}; |
}()); |
|
jsx.python.set.extend(null, { |
}() |
).extend(null, { |
/** |
* @memberOf jsx.python.set.prototype |
*/ |
intersection: function (other) { |
if (!(other instanceof jsx.python.set)) |
{ |
339,7 → 360,7 |
return new jsx.python.set(intersection); |
}, |
|
isdisjoint: function (other) { |
isDisjoint: function (other) { |
return (this.intersection(other).length === 0); |
}, |
|
346,17 → 367,19 |
toArray: function () { |
return this._elements; |
} |
}); |
}), |
|
/** |
* Return an Array of Arrays, where each inner Array contains the i-th |
* element from each of the argument Arrays. The returned Array is |
* truncated in length to the length of the shortest argument Array. |
* Return an {@link Array} of <code>Array</code>s, where each |
* inner array contains the i-th element from each of the |
* argument arrays. |
* The returned <code>Array</code> is truncated in length |
* to the length of the shortest argument array. |
* |
* @param {Array} arg1 |
* @params {Array} |
* @return {Array} |
*/ |
jsx.python.zip = function (arg1, arg2) { |
zip: function () { |
var result = []; |
|
for (var i = 0, len = arguments[0].length; i < len; ++i) |
376,7 → 399,7 |
} |
|
return result; |
}; |
}, |
|
/** |
* Extends an Array with elements from another Array. |
390,9 → 413,11 |
* @param {Array} list2 |
* Array which elements should be appended to <var>list1</var> |
*/ |
jsx.python.extend = function (list1, list2) { |
extend: function (list1, list2) { |
for (var i = 0, len = list2.length; i < len; ++i) |
{ |
Array.prototype.push.call(list1, list2[i]); |
} |
}; |
} |
}; |
}()); |