code
stringlengths
1
2.08M
language
stringclasses
1 value
function main() { // Get the url values var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var userName = urlElements[2]; // Get the site var site = siteService.getSite(shortName); if (site == null) { // Site cannot be found status.setCode(sta...
JavaScript
function main() { // Get the site var shortName = url.extension.split("/")[0]; var site = siteService.getSite(shortName); if (site == null) { // Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist."); return; } /...
JavaScript
function main() { // Get the site var shortName = url.extension.split("/")[0]; var site = siteService.getSite(shortName); if (site == null) { // Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist."); return; } // Get the role var role =...
JavaScript
function main() { // Get the url values var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var userName = urlElements[2]; // Get the site var site = siteService.getSite(shortName); if (site == null) { // Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The...
JavaScript
function main() { // Get the args var siteShortName = url.templateArgs.shortname, site = siteService.getSite(siteShortName), filter = (args.filter != null) ? args.filter : (args.shortNameFilter != null) ? args.shortNameFilter : "", maxResults = (args.maxResults == null) ? 10 : parseInt(args.maxR...
JavaScript
function main() { var shortName = url.templateArgs.shortname; var site = siteService.getSite(shortName); if (site === null) { // Return 404 status.setCode(404, "Site " + shortName + " does not exist"); return; } // calculate the available "roles" and permissions groups for th...
JavaScript
function main() { // Ensure the user has Create Site capability if (!siteService.hasCreateSitePermissions()) { status.setCode(status.STATUS_FORBIDDEN, "error.noPermissions"); return; } // Get the details of the site if (json.has("shortName") == false || json.get("shortName")....
JavaScript
function main() { // Get the filter parameters var nameFilter = args["nf"]; var sitePreset = args["spf"]; var sizeString = args["size"]; // Get the list of sites var sites = siteService.getSites(nameFilter, sitePreset, sizeString != null ? parseInt(sizeString) : -1); model.site...
JavaScript
function main() { // Get the site var shortName = url.extension; var site = siteService.getSite(shortName); if (site != null) { // Updafte the sites details if (json.has("title") == true) { site.title = json.get("title"); } if (json.has("description") == true) { site.descrip...
JavaScript
function main() { var sites = null; // NOTE: // This implementation is sufficient for the 3.1 requirement, but when site query is expanded // it should be formalised in the underlying JS and JAVA API's. Currently it is very simplistic // as the current use case is very limited. ...
JavaScript
function main() { // Get the shortname var shortName = url.extension; // Get the site var site = siteService.getSite(shortName); if (site != null) { // Pass the site to the template model.site = site; } else { // Return 404 status.setCode(404, "...
JavaScript
function main() { // Get the node from the URL var pathSegments = url.match.split("/"); var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); var node = search.findNode(pathSegments[2], reference); // 404 if the node to thumbnail is no...
JavaScript
function main() { // Get the node from the URL var pathSegments = url.match.split("/"); var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); var node = search.findNode(pathSegments[2], reference); // 404 if the node to thumbnail is no...
JavaScript
function main() { // Indicate whether or not the thumbnail can be cached by the browser. Caching is allowed if the lastModified // argument is provided as this is an indication of request uniqueness and therefore the browser will have // the latest thumbnail image. if (args.lastModified != null) { ...
JavaScript
function main() { // Get the node from the URL var pathSegments = url.match.split("/"); var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); var node = search.findNode(pathSegments[2], reference); // 404 if the node to thumbnail is no...
JavaScript
/** * Example JSON: * { * "name" : "myCategory", * "aspect" : "{http://www.alfresco.org/model/content/1.0}generalclassifiable" * } * * where "name" is the name of the new category * "aspect" is an optional field used if creating a root category, it defaults to "{http://www.alfresco.org/model/conten...
JavaScript
/** * Deletes a given category. */ function main() { // Extract template args and build the node reference var nodeRef = url.templateArgs.store_protocol + "://" + url.templateArgs.store_id + "/" + url.templateArgs.node_id; // Log information if (logger.isLoggingEnabled() == true) { logger.lo...
JavaScript
/** * Example JSON: * { * "name" : "myCategory" * } * * where "name" is the name of the new category */ // JSON property values var PROP_NAME = "name"; function main() { // Check we have a json request if (typeof json === "undefined") { if (logger.isWarnLoggingEnabled() == true) { ...
JavaScript
function main() { // Try and get the person var userid = url.templateArgs.userid; var person = people.getPerson(userid); if (person == null) { // 404 since person resource could not be found status.setCode(status.STATUS_NOT_FOUND, "The user " + userid + " could not be found"); return; } ...
JavaScript
function main() { // Try and get the person var userid = url.templateArgs.userid; var person = people.getPerson(userid); if (person == null) { // 404 since person resource could not be found status.setCode(status.STATUS_NOT_FOUND, "The user " + userid + " could not be found"); return; } ...
JavaScript
function main() { // Try and get the person var userid = url.templateArgs.userid; var person = people.getPerson(userid); if (person == null) { // 404 since person resource could not be found status.setCode(status.STATUS_NOT_FOUND, "The user " + userid + " could not be found"); ...
JavaScript
function main() { // Get the user name of the person to get var userName = url.templateArgs.userid; // Get the person who has that user name var person = people.getPerson(userName); if (person === null) { // Return 404 - Not Found status.setCode(statu...
JavaScript
// Get the args var filter = args["filter"]; var maxResults = args["maxResults"]; // Get the collection of people var peopleCollection = people.getPeople(filter, maxResults != null ? parseInt(maxResults) : 0); // Pass the queried sites to the template model.peoplelist = peopleCollection;
JavaScript
function main() { // Extract the person's user name from the URL var userName = url.extension; // Get the person we wish to delete var person = people.getPerson(userName); // if person is found matching the given user name // then delete that person if (person != null) { /...
JavaScript
function main() { // Get the person details and ensure they exist for update var userName = url.extension; var person = people.getPerson(userName); if (person == null) { status.setCode(status.STATUS_NOT_FOUND, "Person " + userName + " does not exist"); return; } // assign new values...
JavaScript
function main() { // Get the user name of the person to get var userName = url.extension; // Do we want to return containing groups? var groups = (args["groups"] == "true"); // Get the person who has that user name var person = people.getPerson(userName); if (person != null) ...
JavaScript
function main() { // // Get the person details // if ((json.isNull("userName")) || (json.get("userName").length() == 0)) { status.setCode(status.STATUS_BAD_REQUEST, "User name missing when creating person"); return; } if ((json.isNull("firstName")) || (json.get("fir...
JavaScript
/** * Delete a wcm web project */ function getWebProject(webprojectref){ var service = webprojects; var data = service.getWebProject(webprojectref) return data; } function main() { // Get the webproject ref var webprojectref = url.extension; if (webprojectref == null || webprojectref.length == 0) ...
JavaScript
/** * Post (create) wcm web project * @return the wcm web project ref */ function main() { var name = json.get("name"); var title = json.get("title"); var dnsName = json.get("dnsName"); var description = json.get("description"); if (name == null || name.length == 0) { status.setCode(status.STATUS_BAD_R...
JavaScript
/** * Get wcm web project * @return the wcm web project */ function getWebProject(webprojectref){ var service = webprojects; var data = service.getWebProject(webprojectref); return data; } function main() { // Get the siteref var webprojectref = url.extension; //var webproject = data; var webproje...
JavaScript
function main() { // Get the url values var urlElements = url.extension.split("/"); var webProjectRef = urlElements[0]; var userName = urlElements[2]; // Get the web project var webproject = webprojects.getWebProject(webProjectRef); if (webproject == null) { // Site cannot be found status.setCode(status.S...
JavaScript
/** * Create a new web project membership * @return */ function main() { // Get the web project var shortName = url.extension.split("/")[0]; var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The web project " + ...
JavaScript
/** * Get the memberships for a web project */ function main() { var shortName = url.extension.split("/")[0]; var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The webproject " + shortName + " does not exist.");...
JavaScript
function main() { // Get the url values var urlElements = url.extension.split("/"); var webProjectRef = urlElements[0]; var userName = urlElements[2]; // Get the web project var webproject = webprojects.getWebProject(webProjectRef); if (webproject == null) { // Site cannot be found status.setCode(status.S...
JavaScript
/** * Delete a wcm web project sandbox */ function main() { var urlElements = url.extension.split("/"); var webprojectref = urlElements[0]; var boxName = urlElements[2]; if (webprojectref == null || webprojectref.length == 0) { status.setCode(status.STATUS_BAD_REQUEST, "Delete sandbox. webprojectref ...
JavaScript
/* * Get the sandbox for a web project */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var sandbox; var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // Site cannot be found status.setCode(st...
JavaScript
/* * Get asset content script */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var pathArray = urlElements.slice(5); var path = pathArray.join("/"); var webproject = webprojects.getWebProject(shortName); if (null == w...
JavaScript
/* * Post -create a new asset file/folder * optionally created with properties and/or simple content */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var boxName = urlElements[2]; var pathArray = urlElements.slice(4); var path = ...
JavaScript
/* * Delete the specified asset from within a sandbox */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var pathArray = urlElements.slice(4); var path = pathArray.join("/"); var webproject = webprojects.getWebProject(shortName); ...
JavaScript
/* * Submit the modified items within a sandbox (JSON) */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; if(!json.has("label")) { status.setCode(status.STATUS_BAD_REQUEST, "property 'label' missing when submitting"); return; ...
JavaScript
/* * Get the modified items within a sandbox */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var sandbox; var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // Site cannot be found...
JavaScript
/* * Update asset - put method */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var pathArray = urlElements.slice(4); var path = pathArray.join("/"); var webproject = webprojects.getWebProject(shortName); if (webproject == null)...
JavaScript
/* * Get asset script */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var pathArray = urlElements.slice(4); var path = pathArray.join("/"); var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // S...
JavaScript
/* * Post -update a asset file/folder * optionally updates simple content */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var pathArray = urlElements.slice(5); var path = pathArray.join("/"); var webproject = webpro...
JavaScript
/* * Revert the modified items within a sandbox (JSON) */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // Web Project cannot be found status.se...
JavaScript
/** * Post (create) wcm web project * @return the wcm web project ref */ function main() { if (!json.has("userName")) { status.setCode(status.STATUS_BAD_REQUEST, "property 'userName' missing when creating sandbox"); return; } var userName = json.get("userName"); if (userName.length == 0) { status...
JavaScript
/* * Get the sandboxes for a web project */ function main() { var shortName = url.extension.split("/")[0]; var sandboxes; var webproject = webprojects.getWebProject(shortName); if (webproject == null) { // Site cannot be found status.setCode(status.STATUS_NOT_FOUND, "The webproject " + shortName + " do...
JavaScript
/** * PUT (UPDATE) wcm web project * @return the updatedwcm web project */ function main() { // Get the webproject ref var webprojectref = url.extension; if (webprojectref == null || webprojectref.length == 0) { status.setCode(status.STATUS_BAD_REQUEST, "Delete web project. webprojectref missing or ...
JavaScript
/** * Get list of wcm web projects * @return the wcm web projects */ function main() { var service = webprojects; var userFilter = args["userName"]; var result; if(userFilter != null) { result = service.listWebProjects(userFilter); } else { result = service.listWebProjects(); } model.webp...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js"> /** * Update a comment */ function updateComment(node) { var title = ""; if (json.has("ti...
JavaScript
/** Name used for the topic that contains all comments. */ const COMMENTS_TOPIC_NAME = "Comments"; /** * Returns all comment nodes for a given node. * @return an array of comments. */ function getComments(node) { var commentsFolder = getCommentsFolder(node); if (commentsFolder !== null) { ...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js"> function main() { // get requested node var node = getRequestNode(); if (status.getCode() ...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/generic-paged-results.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.l...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/nodenameutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js"> ...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js"> /** * Delete a comment. */ function deleteComment(node) { // we simply delete the topic v...
JavaScript
/* * Search related utility functions */ const FUTURE_DATE = "3000\\-12\\-31T00:00:00"; const ZERO_DATE = "1970\\-01\\-01T00:00:00"; /** * Returns the date object for the date "numdays" ago */ function getTodayMinusXDays(numdays) { var date = new Date(); var dateMillis = new Date().getTime(); ...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> function findTargetNode() { if (url.templateArgs.site != undefined) { var siteId = url.templateArgs.site; var containerId = url.templateArgs.container; var path = url.templateArgs.pat...
JavaScript
function main() { // Get the store from the template args var store = "workspace://SpacesStore"; if (url.templateArgs.store_type != null && url.templateArgs.store_id != null) { store = url.templateArgs.store_type + "://" + url.templateArgs.store_id; } // Get the tagName var tagName = url....
JavaScript
function main() { // Get the node from the URL var pathSegments = url.match.split("/"); var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); var node = search.findNode(pathSegments[2], reference); // 404 if the node is not found ...
JavaScript
function main() { // Get the store reference var store = url.templateArgs.store_type + "://" + url.templateArgs.store_id; // Get the details of the tag if (json.has("name") == false || json.get("name").length == 0) { status.setCode(status.STATUS_BAD_REQUEST, "Name missing when creating tag"); ...
JavaScript
function main() { // Get the store reference var store = url.templateArgs.store_type + "://" + url.templateArgs.store_id; var tagNames; var tags = []; var filter = args["tf"]; var details = args["details"]; if (filter === null) { // Get all the tags tagNames...
JavaScript
function main() { // Get the store reference var store = url.templateArgs.store_type + "://" + url.templateArgs.store_id; // Get the tag var tag = url.templateArgs.tag; if (tag == null) { // Error since no tag specified on the URL status.setCode(404, "No tag specified"); ...
JavaScript
function main() { // Get the node from the URL var pathSegments = url.match.split("/"); var reference = [ url.templateArgs.store_type, url.templateArgs.store_id ].concat(url.templateArgs.id.split("/")); var node = search.findNode(pathSegments[2], reference); // 404 if the node is not found ...
JavaScript
function main() { // Get the store from the template args var store = "workspace://SpacesStore"; if (url.templateArgs.store_type != null && url.templateArgs.store_id != null) { store = url.templateArgs.store_type + "://" + url.templateArgs.store_id; } // Get the tagName var tagName = url...
JavaScript
function main() { logger.log("Start workflow form 'Start workflow' webscript"); var docNode = search.findNode("workspace://SpacesStore/" + args.nodeRefId); if (docNode == undefined) { status.code = 404; status.message = "Content with NodeRef id '" + args.nodeRefId + "' not found."; status....
JavaScript
var PeopleCache = {}; /** * Gets / caches a person object * @method getPerson * @param username {string} User name */ function getPerson(username) { if (typeof PeopleCache[username] == "undefined") { var person = people.getPerson(username); if (person == null) { if (u...
JavaScript
// todo // check if previous version was minor or major if no version was submitted // autognerate comment if none was submitted function main() { var nodeRef = json.get("nodeRef"); var version = json.get("version"); var majorVersion = json.get("majorVersion") == "true"; var description = json.g...
JavaScript
/** * Returns a two digit string if it is a one-digit number */ function getTwoDigitNum(num) { if (num < 10) { return "0" + num; } return num; } /** * Returns a unique name that can be used to create a * child of the given parentNode. * * The name will be of form prefix_yyyy-mm-...
JavaScript
function main() { // Task ID var taskId = url.templateArgs.taskId; if (taskId === undefined || taskId == null ) { status.setCode(status.STATUS_BAD_REQUEST, "TaskID missing when ending task."); return; } // TODO Quick-fix, workaround to handle $ being removed from taskId. // C;heck taskId conta...
JavaScript
function extractMetadata(file) { // Extract metadata - via repository action for now. // This should use the MetadataExtracter API to fetch properties, allowing for possible failures. var emAction = actions.create("extract-metadata"); if (emAction != null) { // Call using readOnly = false, n...
JavaScript
/** Name of the blog details aspect. */ const BLOG_DETAILS_ASPECT = "blg:blogDetails"; /** * Fetches the blog properties from the json object and adds them to an array * using the correct property names as indexes. */ function getBlogPropertiesArray() { var arr = new Array(); if (json.has("blogTyp...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js"> const POST_ACTION = "publish"; const UPDATE_ACTION = "update"; const REMOVE_ACTION = "unpublish"; /**...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js"> <import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/blogs/blogpost.lib.js"> /** * Updates the draft mode part of the post */ function updateBlogPostDraftMode(postNode) { //...
JavaScript
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/comments/comments.lib.js"> const ASPECT_SYNDICATION = "cm:syndication"; const PROP_PUBLISHED = "cm:published"; const PROP_UPDATED = "cm:updated"; function setOrUpdateReleasedAndUpdatedDates(node) { // make sure the syndicatio...
JavaScript
/* * Site related utility functions */ /** * Returns the node as specified by the given arguments. * * @param siteId the site for which a node is requested * @param containerId the component to look in for the node. * @param path a path to the node. Returns the root node in case path is null or '' * ...
JavaScript
/** * Returns a data object that can be passed to the paged results template * for rendering. * * @param nodes: The complete result set nodes * @param index: the start index from which results should be returned * @param count: the number of elements that should be returned * @param extractDataFn: The fun...
JavaScript
var searchString = args.search, searchType = args.type, maxResults = args.maxresults, queryString, results = []; if (maxResults == null) { maxResults = 10; } if ((searchString != null) && (searchString != "")) { if (searchType == "tag") { searchString = search.ISO9075Encode(searchString); ...
JavaScript
// Client has requested server-side action /* Inputs */ var runAction = args.a; /* Outputs */ var resultString = "failed", resultCode = false; // Is this action targetting a document? var docNodeId = args.n; if ((docNodeId != "") && (docNodeId != null)) { var docNode = search.findNode("workspace://SpacesStore/...
JavaScript
// Was a document passed-in for New Workflow? if ((args.wd) && (args.wd != "")) { model.docWorkflow = search.findNode("workspace://SpacesStore/" + args.wd); }
JavaScript
if ((args.n) && (args.n != "")) { model.node = search.findNode("workspace://SpacesStore/" + args.n); } // Check here in case invalid nodeRef passed-in if (model.node == null) { if ((args.p) && (args.p != "")) { var path = args.p; if (path == "/" + companyhome.name) { model.node = co...
JavaScript
var query = "TYPE:\"{http://www.alfresco.org/model/content/1.0}person\""; if ((args.s) && (args.s != "")) { query += " AND ("; var terms = args.s.split(" "); for (i = 0; i < terms.length; i++) { term = terms[i]; query += "((@\\{http\\://www.alfresco.org/model/content/1.0\\}firstName:*" + term; ...
JavaScript
(function(Graph, undefined){ Graph.multiMinimumCut = function(graph, times){ /// <summary>gets the minimum number of potential minimum cut in multiple try.<summary> var min = Number.MAX_VALUE, gh, cut, time = []; Math.range(times).forEach(function(){ gh = graph.clone(); time.push(M...
JavaScript
(function(IO, undefined){ IO.fileHandler = function(files, fn){ /// <summary>handles the file from the input DOM.</summary> fn = fn || IO.defaultFn; var reader = new FileReader(); reader.onloadend=function(e) { var requestText = e.target.result, lines; lines = requestText .replace(/^\s\s*/, '...
JavaScript
(function(Math, undefined){ (function(Stats, undefined){ // using x.array.js Stats.max = function(arr){ return firstOrder(arr, function(x, y){return y-x;}, Number.MIN_VALUE); }; Stats.min = function(arr){ return firstOrder(arr, function(x, y){return x-y;}, Number.MAX_VALUE); }; Stats.sum = func...
JavaScript
(function(type, undefined){ // shortcut // _g, the adjacency list of graph, not this // $pt, see wiki type.Graph = function(n, directed){ if (isNaN(n = +n)) { throw new Error(T.ERROR.INVALID_NUMERIC_VALUE); } // gets a unweighted graph, dafualt is undirected graph if (directed !== true){directed = fal...
JavaScript
(function(type, undefined){ // shortcut // _g, the adjacency list of graph, not this // $pt, see wiki type.GraphW = (function(_super){ T.__x__(me, _super); // adgList format (each x in adgList): [v, [[v1, w1], [v2, w2], [v3, w3]...]] = [label, [edgeVertexArray]] function me(n, directed){ _super.call(thi...
JavaScript
(function(Math, undefined){ // i.e. $mod(-1, 4) = 3 Math.mod = function(i, n){ return (i & 0x7FFFFFFF) % n; }; Math.range = function(start, end, step){ // gets a range [start, end) with step var arr = [], i; if (arguments.length == 0){ throw new Error('at least one argument.'); } ...
JavaScript
(function(Sorting, undefined){ // using sorting.js function _partition(arr, l, r, compare){ var i = l, j = r + 1; while (true){ while (compare(arr[++i], arr[l]) < 0) { if (i == r) {break;} } while (compare(arr[l], arr[--j]) < 0) { if ( j== l) {break;} } if (i >= j) {b...
JavaScript
(function(Array, undefined){ var $pt = Array.prototype; // -----API // extended object members of Array: // foldl, foldr: (fn, acc) => acc // map: (fn) => arr // clone: () => arr // static members: // Array.zip: (arr1, arr2) => arr3 $pt.foldl = function(fn, acc){ throw new Error('use Array.reduce instead...
JavaScript
(function(Graph, undefined){ (function(Path, undefined){ Path.floydWarshall = function(){ ///<summary>gets the single source shortest path by bllemanFord algo.</summary> var count = Graph.count(); // [vertexCount, EdgeCount] // A, the array, i, j, k for loop // edges for the edges from v // min is gl...
JavaScript
(function(type, undefined){ var error = {}; Object.defineProperties(error, { 'INVALID_EMPTY_COL_ACTION' : {writable: false, value: 'invalid action on an empty collection'}, 'INVALID_NUMERIC_VALUE' : {writable: false, value: 'invalid numeric value has been passed'}, 'INVALID_GRAPH_ACTION' : {writable: false, ...
JavaScript
(function(Sorting, undefined){ /* * inspired by http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/ */ Sorting.isSorted = function(arr, compare){ // default order by asc compare = Sorting.__compareOrDefault__(compare); var sorted = true, i; for (i=0;i<...
JavaScript
(function(type, undefined){ var _node = function(elem, nextNode){ this.elem = elem; this.next = nextNode || null; }; type.LinkedList = function(){ this.__header__ = new _node('H'); this.__rear__ = this.__header__; this.__length__ = 0; }; // type.LinkedList.merge = function(lst1, lst2){ //...
JavaScript
(function(Graph, undefined){ Graph.mstKruskal = function(){ // gets edge list sorted var edges = Sorting.quickSort(Graph.__edgeList__, function(x){return x[2];}); var T = []; var count = Graph.__countGraph__(); // [vertexCount, EdgeCount] var i, totalCost, u, v; UnionFind.build(count[0]); totalCost ...
JavaScript
(function(Graph, undefined){ (function(Path, undefined){ Path.bellmanFord = function(source){ ///<summary>gets the single source shortest path by bllemanFord algo.</summary> var count = Graph.count(); // [vertexCount, EdgeCount] source = source || 1; // A, the array, i, j, k for loop // edges for the...
JavaScript
(function(Math, undefined){ // using x.array.js // -----API // Point class and its members // new Math.Point(arr), a new Point initialized by its coordinates // this.vector(that), return a new vector build by this and that points // this.polarCompare(p1, p2), return the comparasion for angle between <thi...
JavaScript
/*! blanket - v1.1.5 */ if (typeof QUnit !== 'undefined'){ QUnit.config.autostart = false; } (function(define){ /* Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com> Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be> Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl> Copyright (C) 2...
JavaScript
test('T.LinkedList inserting', function(){ ok((new T.LinkedList()).size() == 0, 'Construct a empty list'); var lst1 = new T.LinkedList(), length = 0, lengthTestMsg = 'Length test success after previous method', rearTestMsg = 'Rear elem test success', peek = function(lst){return lst.__rear__.elem;}; ...
JavaScript
test('Sorting, the basic function', function(){ // test random unique array generator var uniqueArraySort = function(length){ // get an unique random array, sort it, and it is supported to eaqul the array [0, 1..., n-1] length = length || 10; var sortedArray = [], randomArray = [], success = true, i;...
JavaScript
test('T.Stack pushing', function(){ ok((new T.Stack()).size() == 0, 'Construct a empty stack'); var lst1 = new T.Stack(), length = 0, lengthTestMsg = 'Length test success after previous method'; deepEqual(lst1.toArray(), [], 'Empty stack equals []'); strictEqual(lst1.size(), length, lengthTestMsg); ...
JavaScript