_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q45500
train
function(value) { if (value === null) { return []; } else if (Array.isArray(value)) { if (value.every(Selectivity.isValidId)) { return value; } else { throw new Error('Value contains invalid IDs'); } } else { ...
javascript
{ "resource": "" }
q45501
EventListener
train
function EventListener(el, context) { this.context = context || null; this.el = el; this.events = {}; this._onEvent = this._onEvent.bind(this); }
javascript
{ "resource": "" }
q45502
train
function(eventName, selector, callback) { if (!isString(selector)) { callback = selector; selector = ''; } if (callback) { var events = this.events[eventName]; if (events) { events = events[selector]; if (events) { ...
javascript
{ "resource": "" }
q45503
train
function(eventName, selector, callback) { if (!isString(eventName)) { var eventsMap = eventName; for (var key in eventsMap) { if (eventsMap.hasOwnProperty(key)) { var split = key.split(' '); if (split.length > 1) { ...
javascript
{ "resource": "" }
q45504
train
function(options) { var extraClass = options.dropdownCssClass ? ' ' + options.dropdownCssClass : '', searchInput = ''; if (options.showSearchInput) { extraClass += ' has-search-input'; var placeholder = options.searchInputPlaceholder; searchInput = ...
javascript
{ "resource": "" }
q45505
train
function(options) { var extraClass = options.highlighted ? ' highlighted' : ''; return ( '<span class="selectivity-multiple-selected-item' + extraClass + '" ' + 'data-item-id="' + escape(options.id) + '">' + (options.rem...
javascript
{ "resource": "" }
q45506
train
function(options) { return ( '<div class="selectivity-result-item' + (options.disabled ? ' disabled' : '') + '"' + ' data-item-id="' + escape(options.id) + '">' + escape(options.text) + (options.submenu ...
javascript
{ "resource": "" }
q45507
SubmenuPlugin
train
function SubmenuPlugin(selectivity, options) { /** * Optional parent dropdown menu from which this dropdown was opened. */ this.parentMenu = options.parentMenu; Dropdown.call(this, selectivity, options); this._closeSubmenuTimeout = 0; this._openSubmenuTimeout = 0; }
javascript
{ "resource": "" }
q45508
setSelectable
train
function setSelectable(item) { if (item.children) { item.children.forEach(setSelectable); } if (item.submenu) { item.selectable = !!item.selectable; } }
javascript
{ "resource": "" }
q45509
moveHighlight
train
function moveHighlight(dropdown, delta) { var results = dropdown.results; if (!results.length) { return; } var resultItems = [].slice.call(dropdown.el.querySelectorAll('.selectivity-result-item')); function scrollToHighlight() { var el; if (d...
javascript
{ "resource": "" }
q45510
Selectivity
train
function Selectivity(options) { /** * Reference to the currently open dropdown. */ this.dropdown = null; /** * DOM element to which this instance is attached. */ this.el = options.element; /** * Whether the input is enabled. * * This is false when the option read...
javascript
{ "resource": "" }
q45511
train
function() { this.events.destruct(); var el = this.el; while (el.firstChild) { el.removeChild(el.firstChild); } el.selectivity = null; }
javascript
{ "resource": "" }
q45512
train
function(id) { var items = this.items; if (items) { return Selectivity.findNestedById(items, id); } else if (id === null) { return null; } else { return { id: id, text: '' + id }; } }
javascript
{ "resource": "" }
q45513
train
function(elementOrEvent) { var el = elementOrEvent.target || elementOrEvent; while (el) { if (el.hasAttribute('data-item-id')) { break; } el = el.parentNode; } if (!el) { return null; } var id = el.getAttri...
javascript
{ "resource": "" }
q45514
train
function(input, options) { this.input = input; var selectivity = this; var inputListeners = this.options.inputListeners || Selectivity.InputListeners; inputListeners.forEach(function(listener) { listener(selectivity, input, options); }); if (!options || opti...
javascript
{ "resource": "" }
q45515
train
function(newData, options) { options = options || {}; newData = this.validateData(newData); this._data = newData; this._value = this.getValueForData(newData); if (options.triggerChange !== false) { this.triggerChange(); } }
javascript
{ "resource": "" }
q45516
train
function(options) { options = options || {}; var selectivity = this; Selectivity.OptionListeners.forEach(function(listener) { listener(selectivity, options); }); if ('items' in options) { this.items = options.items ? Selectivity.processItems(options.item...
javascript
{ "resource": "" }
q45517
train
function(newValue, options) { options = options || {}; newValue = this.validateValue(newValue); this._value = newValue; if (this.options.initSelection) { this.options.initSelection( newValue, function(data) { if (this._va...
javascript
{ "resource": "" }
q45518
train
function(templateName, options) { var template = this.templates[templateName]; if (!template) { throw new Error('Unknown template: ' + templateName); } if (typeof template === 'function') { var templateResult = template(options); return typeof templat...
javascript
{ "resource": "" }
q45519
train
function(options) { var data = assign({ data: this._data, value: this._value }, options); this.triggerEvent('change', data); this.triggerEvent('selectivity-change', data); }
javascript
{ "resource": "" }
q45520
train
function(eventName, data) { var event = document.createEvent('Event'); event.initEvent(eventName, /* bubbles: */ false, /* cancelable: */ true); assign(event, data); this.el.dispatchEvent(event); return !event.defaultPrevented; }
javascript
{ "resource": "" }
q45521
train
function(item) { if (item && Selectivity.isValidId(item.id) && isString(item.text)) { return item; } else { throw new Error('Item should have id (number or string) and text (string) properties'); } }
javascript
{ "resource": "" }
q45522
EmailInput
train
function EmailInput(options) { MultipleInput.call( this, assign( { createTokenItem: createEmailItem, showDropdown: false, tokenizer: emailTokenizer }, options ) ); this.events.on('blur', function() {...
javascript
{ "resource": "" }
q45523
SelectivityDropdown
train
function SelectivityDropdown(selectivity, options) { this.el = parseElement( selectivity.template('dropdown', { dropdownCssClass: selectivity.options.dropdownCssClass, searchInputPlaceholder: selectivity.options.searchInputPlaceholder, showSearchInput: options.showSearchI...
javascript
{ "resource": "" }
q45524
train
function() { if (!this._closed) { this._closed = true; removeElement(this.el); this.selectivity.events.off('selectivity-selecting', this.close); this.triggerClose(); this._removeScrollListeners(); } }
javascript
{ "resource": "" }
q45525
train
function(item, options) { toggleClass(this.$(HIGHLIGHT_SELECTOR), HIGHLIGHT_CLASS, false); toggleClass(this.$(getItemSelector(RESULT_ITEM_SELECTOR, item.id)), HIGHLIGHT_CLASS, true); this.highlightedResult = item; this.loadMoreHighlighted = false; this.selectivity.triggerEvent(...
javascript
{ "resource": "" }
q45526
train
function() { toggleClass(this.$(HIGHLIGHT_SELECTOR), HIGHLIGHT_CLASS, false); toggleClass(this.$(LOAD_MORE_SELECTOR), HIGHLIGHT_CLASS, true); this.highlightedResult = null; this.loadMoreHighlighted = true; }
javascript
{ "resource": "" }
q45527
train
function() { removeElement(this.$(LOAD_MORE_SELECTOR)); this.resultsContainer.innerHTML += this.selectivity.template('loading'); this.options.query({ callback: function(response) { if (response && response.results) { this._showResults(Selectivity....
javascript
{ "resource": "" }
q45528
train
function(items) { var selectivity = this.selectivity; return items .map(function(item) { var result = selectivity.template(item.id ? 'resultItem' : 'resultLabel', item); if (item.children) { result += selectivity.template('resultChildren', ...
javascript
{ "resource": "" }
q45529
train
function(term) { this.term = term; if (this.options.items) { term = Selectivity.transformText(term); var matcher = this.selectivity.options.matcher || Selectivity.matcher; this._showResults( this.options.items .map(function(item) {...
javascript
{ "resource": "" }
q45530
train
function(id) { var item = Selectivity.findNestedById(this.results, id); if (item && !item.disabled && item.selectable !== false) { var options = { id: id, item: item }; if (this.selectivity.triggerEvent('selectivity-selecting', options)) { this.selectivity.trigger...
javascript
{ "resource": "" }
q45531
train
function(message, options) { this.resultsContainer.innerHTML = this.selectivity.template('error', { escape: !options || options.escape !== false, message: message }); this.hasMore = false; this.results = []; this.highlightedResult = null; this.lo...
javascript
{ "resource": "" }
q45532
train
function() { this.resultsContainer.innerHTML = this.selectivity.template('loading'); this.hasMore = false; this.results = []; this.highlightedResult = null; this.loadMoreHighlighted = false; this.position(); }
javascript
{ "resource": "" }
q45533
train
function(results, options) { if (options.add) { removeElement(this.$('.selectivity-loading')); } else { this.resultsContainer.innerHTML = ''; } var filteredResults = this.selectivity.filterResults(results); var resultsHtml = this.renderItems(filteredResul...
javascript
{ "resource": "" }
q45534
SingleInput
train
function SingleInput(options) { Selectivity.call( this, assign( { // Dropdowns for single-value inputs should open below the select box, unless there // is not enough space below, in which case the dropdown should be moved up just // enough...
javascript
{ "resource": "" }
q45535
train
function(el, selectEl) { var rect = selectEl.getBoundingClientRect(); var dropdownTop = rect.bottom; var deltaUp = Math.min( Math.max(dropdownTop + el.clientHeight - window.innerHeight, 0), rect.top + rect.heigh...
javascript
{ "resource": "" }
q45536
patchEvents
train
function patchEvents($el) { $.each(EVENT_PROPERTIES, function(eventName, properties) { $el.on(eventName, function(event) { if (event.originalEvent) { properties.forEach(function(propertyName) { event[propertyName] = event.originalEvent[propertyName]; ...
javascript
{ "resource": "" }
q45537
LZ4_compress
train
function LZ4_compress (input, options) { var output = [] var encoder = new Encoder(options) encoder.on('data', function (chunk) { output.push(chunk) }) encoder.end(input) return Buffer.concat(output) }
javascript
{ "resource": "" }
q45538
LZ4_uncompress
train
function LZ4_uncompress (input, options) { var output = [] var decoder = new Decoder(options) decoder.on('data', function (chunk) { output.push(chunk) }) decoder.end(input) return Buffer.concat(output) }
javascript
{ "resource": "" }
q45539
colorCoords
train
function colorCoords(channel, color) { let x, y, xmax, ymax; switch (channel) { case 'r': xmax = 255; ymax = 255; x = color.b; y = ymax - color.g; break; case 'g': xmax = 255; ymax = 255; x = color.b; y = ymax - color.r; break; case 'b': ...
javascript
{ "resource": "" }
q45540
colorCoordValue
train
function colorCoordValue(channel, pos) { const color = {}; pos.x = Math.round(pos.x); pos.y = Math.round(pos.y); switch (channel) { case 'r': color.b = pos.x; color.g = 255 - pos.y; break; case 'g': color.b = pos.x; color.r = 255 - pos.y; break; case 'b': c...
javascript
{ "resource": "" }
q45541
train
function(archive) { return { type: "buttercup-archive", exported: Date.now(), format: archive.getFormat(), groups: archive.getGroups().map(group => group.toObject()) }; }
javascript
{ "resource": "" }
q45542
stripDestructiveCommands
train
function stripDestructiveCommands(history) { const destructiveSlugs = Object.keys(Inigo.Command) .map(key => Inigo.Command[key]) .filter(command => command.d) .map(command => command.s); return history.filter(command => { return destructiveSlugs.indexOf(getCommandType(command)) <...
javascript
{ "resource": "" }
q45543
rehydrate
train
function rehydrate(dehydratedString) { const { name, id, sourceCredentials, archiveCredentials, type, colour, order } = JSON.parse(dehydratedString); const source = new ArchiveSource(name, sourceCredentials, archiveCredentials, { id, type }); source.type = type; if (colour) { source._colour = co...
javascript
{ "resource": "" }
q45544
dedupe
train
function dedupe(arr) { return arr.filter(function(item, pos) { return arr.indexOf(item) === pos; }); }
javascript
{ "resource": "" }
q45545
flattenEntries
train
function flattenEntries(archives) { return archives.reduce(function _reduceArchiveEntries(items, archive) { return [ ...items, ...getAllEntries(archive.getGroups()).map(function _expandEntry(entry) { return { entry, archive ...
javascript
{ "resource": "" }
q45546
train
function(movingGroup, target) { let targetArchive, groupDesc; if (target.type === "Archive") { // destination is an archive targetArchive = target; groupDesc = describe(movingGroup._getRemoteObject(), "0"); } else if (target.type === "Group") { // ...
javascript
{ "resource": "" }
q45547
deriveKeyFromPassword
train
function deriveKeyFromPassword(password, salt, rounds, bits) { checkBrowserSupport(); const subtleCrypto = window.crypto.subtle; let params = { name: "PBKDF2", hash: "SHA-256", salt: stringToArrayBuffer(salt), iterations: rounds }, bytes = bits...
javascript
{ "resource": "" }
q45548
credentialsToDatasource
train
function credentialsToDatasource(sourceCredentials) { return Promise.resolve() .then(function() { const datasourceDescriptionRaw = sourceCredentials.getValueOrFail("datasource"); const datasourceDescription = typeof datasourceDescriptionRaw === "string" ...
javascript
{ "resource": "" }
q45549
credentialsToSource
train
function credentialsToSource(sourceCredentials, archiveCredentials, initialise = false, contentOverride = null) { let updated = false; const onUpdate = () => { updated = true; }; return credentialsToDatasource(sourceCredentials) .then(function __handleInitialisation(result) { ...
javascript
{ "resource": "" }
q45550
applyFieldDescriptor
train
function applyFieldDescriptor(entry, descriptor) { setEntryValue(entry, descriptor.field, descriptor.property, descriptor.value); }
javascript
{ "resource": "" }
q45551
consumeEntryFacade
train
function consumeEntryFacade(entry, facade) { const facadeType = getEntryFacadeType(entry); if (facade && facade.type) { const properties = entry.getProperty(); const attributes = entry.getAttribute(); if (facade.type !== facadeType) { throw new Error(`Failed consuming entry d...
javascript
{ "resource": "" }
q45552
setEntryValue
train
function setEntryValue(entry, property, name, value) { switch (property) { case "property": return entry.setProperty(name, value); case "attribute": return entry.setAttribute(name, value); default: throw new Error(`Cannot set value: Unknown property type: ...
javascript
{ "resource": "" }
q45553
train
function(command) { var patt = /("[^"]*")/, quotedStringPlaceholder = "__QUOTEDSTR__", escapedQuotePlaceholder = "__ESCAPED_QUOTE__", matches = [], match; command = command.replace(/\\\"/g, escapedQuotePlaceholder); while ((match = patt.exec(comm...
javascript
{ "resource": "" }
q45554
findEntriesByCheck
train
function findEntriesByCheck(groups, compareFn) { var foundEntries = [], newEntries; groups.forEach(function(group) { newEntries = group.getEntries().filter(compareFn); if (newEntries.length > 0) { foundEntries = foundEntries.concat(newEntries); } newEntries = ...
javascript
{ "resource": "" }
q45555
findGroupsByCheck
train
function findGroupsByCheck(groups, compareFn) { var foundGroups = groups.filter(compareFn); groups.forEach(function(group) { var subFound = findGroupsByCheck(group.getGroups(), compareFn); if (subFound.length > 0) { foundGroups = foundGroups.concat(subFound); } }); re...
javascript
{ "resource": "" }
q45556
getAllEntries
train
function getAllEntries(groups) { return groups.reduce(function(current, group) { const theseEntries = group.getEntries(); const subEntries = getAllEntries(group.getGroups()); if (theseEntries.length > 0) { current = current.concat(theseEntries); } if (subEntries.l...
javascript
{ "resource": "" }
q45557
calculateCommonRecentCommand
train
function calculateCommonRecentCommand(archiveA, archiveB) { var historyA = archiveA._getWestley().getHistory(), historyB = archiveB._getWestley().getHistory(), aLen = historyA.length, bLen = historyB.length, a, b; for (a = aLen - 1; a >= 0; a -= 1) { if (getComman...
javascript
{ "resource": "" }
q45558
createFieldDescriptor
train
function createFieldDescriptor( entry, title, entryPropertyType, entryPropertyName, { multiline = false, secret = false, formatting = false, removeable = false } = {} ) { const value = getEntryValue(entry, entryPropertyType, entryPropertyName); return { title, field: entryPro...
javascript
{ "resource": "" }
q45559
getEntryURLs
train
function getEntryURLs(properties, preference = ENTRY_URL_TYPE_ANY) { const urlRef = Object.keys(properties) .filter(key => URL_PROP.test(key)) .reduce( (output, nextKey) => Object.assign(output, { [nextKey]: properties[nextKey] }), ...
javascript
{ "resource": "" }
q45560
getEntryValue
train
function getEntryValue(entry, property, name) { switch (property) { case "property": return entry.getProperty(name); case "meta": return entry.getMeta(name); case "attribute": return entry.getAttribute(name); default: throw new Error(`C...
javascript
{ "resource": "" }
q45561
isValidProperty
train
function isValidProperty(name) { for (var keyName in EntryProperty) { if (EntryProperty.hasOwnProperty(keyName)) { if (EntryProperty[keyName] === name) { return true; } } } return false; }
javascript
{ "resource": "" }
q45562
scheduleExecution
train
function scheduleExecution(step, clearContainerCache, contexts) { if (!scheduledCall) { scheduledCall = { _step: step, _clearContainerCache: clearContainerCache, _contexts: contexts, }; requestAnimationFrame(executeScheduledCall); return; } scheduledCall._step = Math.min(scheduledCall._step, step)...
javascript
{ "resource": "" }
q45563
startObserving
train
function startObserving() { if (config.skipObserving) { return; } // Reprocess now scheduleExecution(1); window.addEventListener('DOMContentLoaded', scheduleExecution.bind(undefined, 1, undefined, undefined)); window.addEventListener('load', scheduleExecution.bind(undefined, 1, undefined, undefined)); windo...
javascript
{ "resource": "" }
q45564
checkMutations
train
function checkMutations(mutations) { // Skip iterating the nodes, if a run is already scheduled, to improve performance if (scheduledCall && (scheduledCall._level < 3 || !scheduledCall._contexts)) { return; } var addedNodes = []; var stylesChanged = false; var replacedSheets = []; processedSheets.forEach(fu...
javascript
{ "resource": "" }
q45565
onDomMutate
train
function onDomMutate(event) { var mutation = { addedNodes: [], removedNodes: [], }; mutation[ (event.type === 'DOMNodeInserted' ? 'added' : 'removed') + 'Nodes' ] = [event.target]; domMutations.push(mutation); // Delay the call to checkMutations() setTimeout(function() { checkMutations(domMutations); ...
javascript
{ "resource": "" }
q45566
loadExternal
train
function loadExternal(href, callback) { var cacheEntryType = typeof requestCache[href]; if (cacheEntryType === 'string') { callback(requestCache[href]); return; } else if (cacheEntryType === 'object') { requestCache[href].push(callback); return; } requestCache[href] = [callback] var isDone = false; var ...
javascript
{ "resource": "" }
q45567
fixRelativeUrls
train
function fixRelativeUrls(cssText, href) { var base = resolveRelativeUrl(href, document.baseURI); return cssText.replace(URL_VALUE_REGEXP, function(match, quote, url1, url2) { var url = url1 || url2; if (!url) { return match; } return 'url(' + (quote || '"') + resolveRelativeUrl(url, base) + (quote || '"') ...
javascript
{ "resource": "" }
q45568
buildStyleCache
train
function buildStyleCache() { styleCache = { width: {}, height: {}, }; var rules; for (var i = 0; i < styleSheets.length; i++) { if (styleSheets[i].disabled) { continue; } try { rules = styleSheets[i].cssRules; if (!rules || !rules.length) { continue; } } catch(e) { continue; } b...
javascript
{ "resource": "" }
q45569
updateClassesRead
train
function updateClassesRead(treeNodes, dontMarkAsDone) { var hasChanges = false; var i, node, j, query; for (i = 0; i < treeNodes.length; i++) { node = treeNodes[i]; if (!node._done) { for (j = 0; j < node._queries.length; j++) { query = node._queries[j]; var queryMatches = evaluateQuery(node._element....
javascript
{ "resource": "" }
q45570
updateClassesWrite
train
function updateClassesWrite(treeNodes) { var node, j; for (var i = 0; i < treeNodes.length; i++) { node = treeNodes[i]; for (j = 0; j < node._changes.length; j++) { (node._changes[j][0] ? addQuery : removeQuery)(node._element, node._changes[j][1]); } node._changes = []; updateClassesWrite(node._children)...
javascript
{ "resource": "" }
q45571
buildElementsTree
train
function buildElementsTree(contexts) { contexts = contexts || [document]; var queriesArray = Object.keys(queries).map(function(key) { return queries[key]; }); var selector = queriesArray.map(function(query) { return query._selector; }).join(','); var elements = []; contexts.forEach(function(context) { ...
javascript
{ "resource": "" }
q45572
evaluateQuery
train
function evaluateQuery(parent, query) { var container = getContainer(parent, query._prop); var qValues = query._values.slice(0); var i; var cValue; if (query._prop === 'width' || query._prop === 'height') { cValue = getSize(container, query._prop); } else { cValue = getComputedStyle(container).getPropertyV...
javascript
{ "resource": "" }
q45573
getContainer
train
function getContainer(element, prop) { var cache; if (containerCache.has(element)) { cache = containerCache.get(element); if (cache[prop]) { return cache[prop]; } } else { cache = {}; containerCache.set(element, cache); } if (element === documentElement) { cache[prop] = element; } else if (pro...
javascript
{ "resource": "" }
q45574
isIntrinsicSize
train
function isIntrinsicSize(element, prop) { var computedStyle = getComputedStyle(element); if (computedStyle.display === 'none') { return false; } if (computedStyle.display === 'inline') { return true; } // Non-floating non-absolute block elements (only width) if ( prop === 'width' && ['block', 'list-i...
javascript
{ "resource": "" }
q45575
getSize
train
function getSize(element, prop) { var style = getComputedStyle(element); if (prop === 'width') { return element.offsetWidth - parseFloat(style.borderLeftWidth) - parseFloat(style.paddingLeft) - parseFloat(style.borderRightWidth) - parseFloat(style.paddingRight); } else { return element.offsetHeight ...
javascript
{ "resource": "" }
q45576
getComputedLength
train
function getComputedLength(value, element) { var length = value.match(LENGTH_REGEXP); if (!length) { return parseFloat(value); } value = parseFloat(length[1]); var unit = length[2].toLowerCase(); if (FIXED_UNIT_MAP[unit]) { return value * FIXED_UNIT_MAP[unit]; } if (unit === 'vw') { return value * window....
javascript
{ "resource": "" }
q45577
getOriginalStyle
train
function getOriginalStyle(element, prop) { var matchedRules = []; var value; var j; matchedRules = sortRulesBySpecificity( filterRulesByElementAndProp(styleCache[prop], element, prop) ); // Add style attribute matchedRules.unshift({ _rule: { style: element.style, }, }); // Loop through all importa...
javascript
{ "resource": "" }
q45578
parseColor
train
function parseColor(color) { // Let the browser round the RGBA values for consistency parseColorStyle.cssText = 'color:' + color; color = parseColorStyle.color; if (!color || !color.split || !color.split('(')[1]) { return [0, 0, 0, 0]; } color = color.split('(')[1].split(',').map(parseFloat); if (color[3] ...
javascript
{ "resource": "" }
q45579
filterRulesByElementAndProp
train
function filterRulesByElementAndProp(rules, element, prop) { var foundRules = []; if (element.id) { foundRules = foundRules.concat(rules['#' + element.id] || []); } (element.getAttribute('class') || '').split(/\s+/).forEach(function(className) { foundRules = foundRules.concat(rules['.' + className] || []); });...
javascript
{ "resource": "" }
q45580
createCacheMap
train
function createCacheMap() { if (typeof Map === 'function') { return new Map(); } var keys = []; var values = []; function getIndex(key) { return keys.indexOf(key); } function get(key) { return values[getIndex(key)]; } function has(key) { return getIndex(key) !== -1; } function set(key, value) {...
javascript
{ "resource": "" }
q45581
arrayFrom
train
function arrayFrom(arrayLike) { if (Array.from) { return Array.from(arrayLike); } var array = []; for (var i = 0; i < arrayLike.length; i++) { array[i] = arrayLike[i]; } return array; }
javascript
{ "resource": "" }
q45582
indexOfElementInArray
train
function indexOfElementInArray(element, array) { if (!array) return -1; if (array.indexOf) { return array.indexOf(element); } var len = array.length, i; for (i = 0; i < len; i += 1) { if (array[i] === element) { return i; } } return -1; }
javascript
{ "resource": "" }
q45583
Link
train
function Link(fromId, toId, data, id) { this.fromId = fromId; this.toId = toId; this.data = data; this.id = id; }
javascript
{ "resource": "" }
q45584
train
function(freq, alphabetSize) { // As in BZip2HuffmanStageEncoder.java (from jbzip2): // The Huffman allocator needs its input symbol frequencies to be // sorted, but we need to return code lengths in the same order as // the corresponding frequencies are passed in. // The symbol frequency and index are merged...
javascript
{ "resource": "" }
q45585
train
function(inStream, block, length, crc) { var pos = 0; var lastChar = -1; var runLength = 0; while (pos < length) { if (runLength===4) { block[pos++] = 0; if (pos >= length) { break; } } var ch = inStream.readByte(); if (ch === EOF) { break; } crc.updateCRC(ch); if (...
javascript
{ "resource": "" }
q45586
train
function(selectors, groups, input) { var i, j, k; for (i=0, k=0; i<input.length; i+=GROUP_SIZE) { var groupSize = Math.min(GROUP_SIZE, input.length - i); var best = 0, bestCost = groups[0].cost(input, i, groupSize); for (j=1; j<groups.length; j++) { var groupCost = groups[j].cost(input, i, groupSi...
javascript
{ "resource": "" }
q45587
train
function(array) { var length = array.length; array[0] += array[1]; var headNode, tailNode, topNode, temp; for (headNode = 0, tailNode = 1, topNode = 2; tailNode < (length - 1); tailNode++) { if ((topNode >= length) || (array[headNode] < array[topNode])) { temp = array[h...
javascript
{ "resource": "" }
q45588
train
function(array, maximumLength) { var currentNode = array.length - 2; var currentDepth; for (currentDepth = 1; (currentDepth < (maximumLength - 1)) && (currentNode > 1); currentDepth++) { currentNode = first (array, currentNode - 1, 0); } return currentNode; }
javascript
{ "resource": "" }
q45589
train
function(array) { var firstNode = array.length - 2; var nextNode = array.length - 1; var currentDepth, availableNodes, lastNode, i; for (currentDepth = 1, availableNodes = 2; availableNodes > 0; currentDepth++) { lastNode = firstNode; firstNode = first (array, lastNode - 1...
javascript
{ "resource": "" }
q45590
train
function(array, nodesToMove, insertDepth) { var firstNode = array.length - 2; var nextNode = array.length - 1; var currentDepth = (insertDepth == 1) ? 2 : 1; var nodesLeftToMove = (insertDepth == 1) ? nodesToMove - 2 : nodesToMove; var availableNode...
javascript
{ "resource": "" }
q45591
train
function(array, maximumLength) { switch (array.length) { case 2: array[1] = 1; case 1: array[0] = 1; return; } /* Pass 1 : Set extended parent pointers */ setExtendedParentPointers (array); /* Pass 2 : Find number of nodes to relocate in order to achieve * m...
javascript
{ "resource": "" }
q45592
train
function(size, extraStates, lgDistanceModelFactory, lengthBitsModelFactory) { var i; var bits = Util.fls(size-1); this.extraStates = +extraStates || 0; this.lgDistanceModel = lgDistanceModelFactory(2*bits + e...
javascript
{ "resource": "" }
q45593
train
function(T, C, n, k) { var i; for (i = 0; i < k; i++) { C[i] = 0; } for (i = 0; i < n; i++) { C[T[i]]++; } }
javascript
{ "resource": "" }
q45594
train
function(T, SA, C, B, n, k) { var b, i, j; var c0, c1; /* compute SAl */ if (C === B) { getCounts(T, C, n, k); } getBuckets(C, B, k, false); /* find starts of buckets */ j = n - 1; b = B[c1 = T[j]]; j--; SA[b++] = (T[j] < c1) ? ~j : j; for ...
javascript
{ "resource": "" }
q45595
train
function(size, root, bitstream, max_weight) { var i; // default: all alphabet symbols are used console.assert(size && typeof(size)==='number'); if( !root || root > size ) root = size; // create the initial escape node // at the tree root if ( root <<= 1 ) { root--; } // create root+...
javascript
{ "resource": "" }
q45596
pathToLines
train
function pathToLines(path) { var lines = []; var curr = null; path.forEach(function(cmd) { if(cmd[0] == PATH_COMMAND.MOVE) { curr = cmd[1]; } if(cmd[0] == PATH_COMMAND.LINE) { var pt = cmd[1]; lines.push(new Line(curr, pt)); curr = pt;...
javascript
{ "resource": "" }
q45597
calcBezierAtT
train
function calcBezierAtT(p, t) { var x = (1-t)*(1-t)*(1-t)*p[0].x + 3*(1-t)*(1-t)*t*p[1].x + 3*(1-t)*t*t*p[2].x + t*t*t*p[3].x; var y = (1-t)*(1-t)*(1-t)*p[0].y + 3*(1-t)*(1-t)*t*p[1].y + 3*(1-t)*t*t*p[2].y + t*t*t*p[3].y; return new Point(x, y); }
javascript
{ "resource": "" }
q45598
calcMinimumBounds
train
function calcMinimumBounds(lines) { var bounds = { x: Number.MAX_VALUE, y: Number.MAX_VALUE, x2: Number.MIN_VALUE, y2: Number.MIN_VALUE } function checkPoint(pt) { bounds.x = Math.min(bounds.x,pt.x); bounds.y = Math.min(bounds.y,pt.y); bounds.x2 = Math.max(bounds.x2,pt.x); ...
javascript
{ "resource": "" }
q45599
calcSortedIntersections
train
function calcSortedIntersections(lines,y) { var xlist = []; for(var i=0; i<lines.length; i++) { var A = lines[i].start; var B = lines[i].end; if(A.y<y && B.y>=y || B.y<y && A.y>=y) { var xval = A.x + (y-A.y) / (B.y-A.y) * (B.x-A.x); xlist.push(xval); } ...
javascript
{ "resource": "" }