_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q47700
train
function ( geometry, n ) { var face, i, faces = geometry.faces, vertices = geometry.vertices, il = faces.length, totalArea = 0, cumulativeAreas = [], vA, vB, vC, vD; // precompute face areas for ( i = 0; i < il; i ++ ) { face = faces[ i ]; if ( face instanceof THREE.Face3 ) { vA ...
javascript
{ "resource": "" }
q47701
train
function( geometry ) { var vertices = []; for ( var i = 0, il = geometry.faces.length; i < il; i ++ ) { var n = vertices.length; var face = geometry.faces[ i ]; if ( face instanceof THREE.Face4 ) { var a = face.a; var b = face.b; var c = face.c; var d = face.d; var va = geometry....
javascript
{ "resource": "" }
q47702
train
function( ax, ay, bx, by, cx, cy, px, py ) { var aX, aY, bX, bY; var cX, cY, apx, apy; var bpx, bpy, cpx, cpy; var cCROSSap, bCROSScp, aCROSSbp; aX = cx - bx; aY = cy - by; bX = ax - cx; bY = ay - cy; cX = bx - ax; cY = by - ay; apx= px -ax; apy= p...
javascript
{ "resource": "" }
q47703
addVertexEdgeMap
train
function addVertexEdgeMap(vertex, edge) { if (vertexEdgeMap[vertex]===undefined) { vertexEdgeMap[vertex] = []; } vertexEdgeMap[vertex].push(edge); }
javascript
{ "resource": "" }
q47704
levenshteinForStrings
train
function levenshteinForStrings(a, b) { if (a === b) return 0; const tmp = a; // Swapping the strings so that the shorter string is the first one. if (a.length > b.length) { a = b; b = tmp; } let la = a.length, lb = b.length; if (!la) return lb; if (!lb) return la; // Ign...
javascript
{ "resource": "" }
q47705
caverphone
train
function caverphone(rules, name) { if (typeof name !== 'string') throw Error('talisman/phonetics/caverphone: the given name is not a string.'); // Preparing the name name = deburr(name) .toLowerCase() .replace(/[^a-z]/g, ''); // Applying the rules for (let i = 0, l = rules.length; i < l; i++) {...
javascript
{ "resource": "" }
q47706
indexOf
train
function indexOf(haystack, needle) { if (typeof haystack === 'string') return haystack.indexOf(needle); for (let i = 0, j = 0, l = haystack.length, n = needle.length; i < l; i++) { if (haystack[i] === needle[j]) { j++; if (j === n) return i - j + 1; } else { j = 0; } ...
javascript
{ "resource": "" }
q47707
matches
train
function matches(a, b) { const stack = [a, b]; let m = 0; while (stack.length) { a = stack.pop(); b = stack.pop(); if (!a.length || !b.length) continue; const lcs = (new GeneralizedSuffixArray([a, b]).longestCommonSubsequence()), length = lcs.length; if (!length) con...
javascript
{ "resource": "" }
q47708
customJaroWinkler
train
function customJaroWinkler(options, a, b) { options = options || {}; const { boostThreshold = 0.7, scalingFactor = 0.1 } = options; if (scalingFactor > 0.25) throw Error('talisman/metrics/distance/jaro-winkler: the scaling factor should not exceed 0.25.'); if (boostThreshold < 0 || boostThresho...
javascript
{ "resource": "" }
q47709
applyRules
train
function applyRules(rules, stem) { for (let i = 0, l = rules.length; i < l; i++) { const [min, pattern, replacement = ''] = rules[i]; if (stem.slice(-pattern.length) === pattern) { const newStem = stem.slice(0, -pattern.length) + replacement, m = computeM(newStem); if (m <= min) ...
javascript
{ "resource": "" }
q47710
genericVariance
train
function genericVariance(ddof, sequence) { const length = sequence.length; if (!length) throw Error('talisman/stats/inferential#variance: the given list is empty.'); // Returning 0 if the denominator would be <= 0 const denominator = length - ddof; if (denominator <= 0) return 0; const m = mean(...
javascript
{ "resource": "" }
q47711
genericStdev
train
function genericStdev(ddof, sequence) { const v = genericVariance(ddof, sequence); return Math.sqrt(v); }
javascript
{ "resource": "" }
q47712
withoutTranspositions
train
function withoutTranspositions(maxOffset, maxDistance, a, b) { // Early termination if (a === b) return 0; const la = a.length, lb = b.length; if (!la || !lb) return Math.max(la, lb); let cursorA = 0, cursorB = 0, longestCommonSubsequence = 0, localCommonSubstring = 0; ...
javascript
{ "resource": "" }
q47713
withTranspositions
train
function withTranspositions(maxOffset, maxDistance, a, b) { // Early termination if (a === b) return 0; const la = a.length, lb = b.length; if (!la || !lb) return Math.max(la, lb); let cursorA = 0, cursorB = 0, longestCommonSubsequence = 0, localCommonSubstring = 0, ...
javascript
{ "resource": "" }
q47714
createContext
train
function createContext(sentence) { const context = new Array(sentence.length + 4); context[0] = START[0]; context[1] = START[1]; for (let j = 0, m = sentence.length; j < m; j++) context[j + 2] = normalize(sentence[j][0]); context[context.length - 2] = END[0]; context[context.length - 1] = ...
javascript
{ "resource": "" }
q47715
transferCase
train
function transferCase(source, target) { let cased = ''; for (let i = 0, l = target.length; i < l; i++) { const c = source[i].toLowerCase() === source[i] ? 'toLowerCase' : 'toUpperCase'; cased += target[i][c](); } return cased; }
javascript
{ "resource": "" }
q47716
nysiis
train
function nysiis(type, name) { if (typeof name !== 'string') throw Error('talisman/phonetics/nysiis: the given name is not a string.'); // Preparing the string name = deburr(name) .toUpperCase() .trim() .replace(/[^A-Z]/g, ''); // Getting the proper patterns const patterns = PATTERNS[type]; ...
javascript
{ "resource": "" }
q47717
frequencies
train
function frequencies(sequence) { const index = {}; // Handling strings sequence = seq(sequence); for (let i = 0, l = sequence.length; i < l; i++) { const element = sequence[i]; if (!index[element]) index[element] = 0; index[element]++; } return index; }
javascript
{ "resource": "" }
q47718
relativeFrequencies
train
function relativeFrequencies(sequence) { let index, length; // Handling the object polymorphism if (typeof sequence === 'object' && !Array.isArray(sequence)) { index = sequence; length = 0; for (const k in index) length += index[k]; } else { length = sequence.length; index = ...
javascript
{ "resource": "" }
q47719
dunningLogLikelihood
train
function dunningLogLikelihood(a, b, ab, N) { const p1 = b / N, p2 = 0.99; const nullHypothesis = ab * Math.log(p1) + (a - ab) * Math.log(1 - p1), alternativeHyphothesis = ab * Math.log(p2) + (a - ab) * Math.log(1 - p2); const likelihood = nullHypothesis - alternativeHyphothesis; return (-2 * ...
javascript
{ "resource": "" }
q47720
colLogLikelihood
train
function colLogLikelihood(a, b, ab, N) { const p = b / N, p1 = ab / a, p2 = (b - ab) / (N - a); const summand1 = ab * Math.log(p) + (a - ab) * Math.log(1 - p), summand2 = (b - ab) * Math.log(p) + (N - a - b + ab) * Math.log(1 - p); let summand3 = 0; if (a !== ab) summand3 = ab * Ma...
javascript
{ "resource": "" }
q47721
train
function( name, value ) { if ( completed == null ) { name = requestHeadersNames[ name.toLowerCase() ] = requestHeadersNames[ name.toLowerCase() ] || name; requestHeaders[ name ] = value; } return this; }
javascript
{ "resource": "" }
q47722
reflowText
train
function reflowText (text, width, gfm) { // Hard break was inserted by Renderer.prototype.br or is // <br /> when gfm is true var splitRe = gfm ? HARD_RETURN_GFM_RE : HARD_RETURN_RE, sections = text.split(splitRe), reflowed = []; sections.forEach(function (section) { // Split the section by esc...
javascript
{ "resource": "" }
q47723
fixNestedLists
train
function fixNestedLists (body, indent) { var regex = new RegExp('' + '(\\S(?: | )?)' + // Last char of current point, plus one or two spaces // to allow trailing spaces '((?:' + indent + ')+)' + // Indentation of sub point '(' + POINT_REGEX + '(?:.*)+)$', 'gm'); // Body of subpoint...
javascript
{ "resource": "" }
q47724
map
train
function map(tree, method, args) { return tree.model[method].apply(tree.model, args); }
javascript
{ "resource": "" }
q47725
getPredicateFunction
train
function getPredicateFunction(predicate) { let fn = predicate; if (_.isString(predicate)) { fn = node => (_.isFunction(node[predicate]) ? node[predicate]() : node[predicate]); } return fn; }
javascript
{ "resource": "" }
q47726
baseStatePredicate
train
function baseStatePredicate(state, full) { if (full) { return this.extract(state); } // Cache a state predicate function const fn = getPredicateFunction(state); return this.flatten(node => { // Never include removed nodes unless specifically requested if (state !== 'removed...
javascript
{ "resource": "" }
q47727
cloneItree
train
function cloneItree(itree, excludeKeys) { const clone = {}; excludeKeys = _.castArray(excludeKeys); excludeKeys.push('ref'); _.each(itree, (v, k) => { if (!_.includes(excludeKeys, k)) { clone[k] = _.cloneDeep(v); } }); return clone; }
javascript
{ "resource": "" }
q47728
baseState
train
function baseState(node, property, val) { const currentVal = node.itree.state[property]; if (typeof val !== 'undefined' && currentVal !== val) { // Update values node.itree.state[property] = val; if (property !== 'rendered') { node.markDirty(); } // Emit an...
javascript
{ "resource": "" }
q47729
resetState
train
function resetState(node) { _.each(node._tree.defaultState, (val, prop) => { node.state(prop, val); }); return node; }
javascript
{ "resource": "" }
q47730
run
train
async function run() { const fetcher = new ChangelogFetcher({ base, futureRelease, futureReleaseTag, labels, owner, repo, token }); const releases = await fetcher.fetchChangelog(); formatChangelog(releases).forEach(line => process.stdout.write(line)); }
javascript
{ "resource": "" }
q47731
train
function (element, event) { var pageX = (event.changedTouches) ? event.changedTouches[0].pageX : event.pageX; var offsetx = pageX - $(element).offset().left; if (!ltr) { offsetx = range.width() - offsetx }; if (offsetx > range.width()) { offsetx = range.w...
javascript
{ "resource": "" }
q47732
train
function (score) { var w = score * itemdata('starwidth') * itemdata('step'); var h = range.find('.rateit-hover'); if (h.data('width') != w) { range.find('.rateit-selected').hide(); h.width(w).show().data('width', w); ...
javascript
{ "resource": "" }
q47733
getRenderedCenter
train
function getRenderedCenter(target, renderedDimensions){ let pos = target.renderedPosition(); let dimensions = renderedDimensions(target); let offsetX = dimensions.w / 2; let offsetY = dimensions.h / 2; return { x : (pos.x - offsetX), y : (pos.y - offsetY) }; }
javascript
{ "resource": "" }
q47734
getRenderedMidpoint
train
function getRenderedMidpoint(target){ let p = target.midpoint(); let pan = target.cy().pan(); let zoom = target.cy().zoom(); return { x: p.x * zoom + pan.x, y: p.y * zoom + pan.y }; }
javascript
{ "resource": "" }
q47735
getPopper
train
function getPopper(target, opts) { let refObject = getRef(target, opts); let content = getContent(target, opts.content); let popperOpts = assign({}, popperDefaults, opts.popper); return new Popper(refObject, content, popperOpts); }
javascript
{ "resource": "" }
q47736
createOptionsObject
train
function createOptionsObject(target, opts) { let defaults = { boundingBox : { top: 0, left: 0, right: 0, bottom: 0, w: 3, h: 3, }, renderedDimensions : () => ({w: 3, h: 3}), redneredPosition : () => ({x : 0, y : 0}), popper : {}, cy : target }; return a...
javascript
{ "resource": "" }
q47737
ensureWindows
train
function ensureWindows () { if (process.platform !== 'win32') { log('This tool requires Windows 10.\n') log('You can run a virtual machine using the free VirtualBox and') log('the free Windows Virtual Machines found at http://modern.ie.\n') log('For more information, please see the readme.') proce...
javascript
{ "resource": "" }
q47738
hasVariableResources
train
function hasVariableResources (assetsDirectory) { const files = require('fs-extra').readdirSync(assetsDirectory) const hasScale = files.find(file => /\.scale-...\./g.test(file)) return (!!hasScale) }
javascript
{ "resource": "" }
q47739
executeChildProcess
train
function executeChildProcess (fileName, args, options) { return new Promise((resolve, reject) => { const child = require('child_process').spawn(fileName, args, options) child.stdout.on('data', (data) => log(data.toString())) child.stderr.on('data', (data) => log(data.toString())) child.on('exit', (c...
javascript
{ "resource": "" }
q47740
isSetupRequired
train
function isSetupRequired (program) { const config = dotfile.get() || {} const hasPublisher = (config.publisher || program.publisher) const hasDevCert = (config.devCert || program.devCert) const hasWindowsKit = (config.windowsKit || program.windowsKit) const hasBaseImage = (config.expandedBaseImage || program....
javascript
{ "resource": "" }
q47741
wizardSetup
train
function wizardSetup (program) { const welcome = multiline.stripIndent(function () { /* Welcome to the Electron-Windows-Store tool! This tool will assist you with turning your Electron app into a swanky Windows Store app. We need to know some settings. We will ask you only once and s...
javascript
{ "resource": "" }
q47742
logConfiguration
train
function logConfiguration (program) { utils.log(chalk.bold.green.underline('\nConfiguration: ')) utils.log(`Desktop Converter Location: ${program.desktopConverter}`) utils.log(`Expanded Base Image: ${program.expandedBaseImage}`) utils.log(`Publisher: ${program.publisher}`) uti...
javascript
{ "resource": "" }
q47743
setup
train
function setup (program) { return new Promise((resolve, reject) => { if (isSetupRequired(program)) { // If we're setup, merge the dotfile configuration into the program defaults(program, dotfile.get()) logConfiguration(program) resolve() } else { // We're not setup, let's do that...
javascript
{ "resource": "" }
q47744
convertWithContainer
train
function convertWithContainer (program) { return new Promise((resolve, reject) => { if (!program.desktopConverter) { utils.log('Could not find the Project Centennial Desktop App Converter, which is required to') utils.log('run the conversion to appx using a Windows Container.\n') utils.log('Cons...
javascript
{ "resource": "" }
q47745
specialRequire
train
function specialRequire(name, fromDir) { if (!fromDir) fromDir = process.cwd(); var paths = Module._nodeModulePaths(fromDir); var path = Module._findPath(name, paths); return path ? require(path) : require(name); }
javascript
{ "resource": "" }
q47746
_transform
train
function _transform() { var codeIn = $('#codeIn').val(); try { var codeOut = Streamline.transform(codeIn, { runtime: _generators ? "generators" : "callbacks", }); $('#codeOut').val(codeOut); info("ready"); } catch (ex) { console.error(ex); error(ex.message); } }
javascript
{ "resource": "" }
q47747
onFinished
train
function onFinished (msg, listener) { if (isFinished(msg) !== false) { defer(listener, null, msg) return msg } // attach the listener to the message attachListener(msg, listener) return msg }
javascript
{ "resource": "" }
q47748
isFinished
train
function isFinished (msg) { var socket = msg.socket if (typeof msg.finished === 'boolean') { // OutgoingMessage return Boolean(msg.finished || (socket && !socket.writable)) } if (typeof msg.complete === 'boolean') { // IncomingMessage return Boolean(msg.upgrade || !socket || !socket.readable |...
javascript
{ "resource": "" }
q47749
attachFinishedListener
train
function attachFinishedListener (msg, callback) { var eeMsg var eeSocket var finished = false function onFinish (error) { eeMsg.cancel() eeSocket.cancel() finished = true callback(error) } // finished on first message event eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish) ...
javascript
{ "resource": "" }
q47750
attachListener
train
function attachListener (msg, listener) { var attached = msg.__onFinished // create a private single listener with queue if (!attached || !attached.queue) { attached = msg.__onFinished = createListener(msg) attachFinishedListener(msg, attached) } attached.queue.push(listener) }
javascript
{ "resource": "" }
q47751
createListener
train
function createListener (msg) { function listener (err) { if (msg.__onFinished === listener) msg.__onFinished = null if (!listener.queue) return var queue = listener.queue listener.queue = null for (var i = 0; i < queue.length; i++) { queue[i](err, msg) } } listener.queue = [] ...
javascript
{ "resource": "" }
q47752
patchAssignSocket
train
function patchAssignSocket (res, callback) { var assignSocket = res.assignSocket if (typeof assignSocket !== 'function') return // res.on('socket', callback) is broken in 0.8 res.assignSocket = function _assignSocket (socket) { assignSocket.call(this, socket) callback(socket) } }
javascript
{ "resource": "" }
q47753
parseLdOutput
train
function parseLdOutput(output) { const libraryList = output.split('\n').filter(ln => ln.includes('=>')); const result = {}; libraryList.forEach(s => { const [name, _, libPath] = s.trim().split(' '); result[name] = libPath; }); return result; }
javascript
{ "resource": "" }
q47754
BaseNode
train
function BaseNode (nodeId, log, connection, options) { /** * Unique current machine name. * @type {string} * * @example * console.log(node.localNodeId + ' is started') */ this.localNodeId = nodeId /** * Log for synchronization. * @type {Log} */ this.log = log /** * Connection use...
javascript
{ "resource": "" }
q47755
destroy
train
function destroy () { if (this.connection.destroy) { this.connection.destroy() } else if (this.connected) { this.connection.disconnect('destroy') } for (var i = 0; i < this.unbind.length; i++) { this.unbind[i]() } clearTimeout(this.pingTimeout) this.endTimeout() }
javascript
{ "resource": "" }
q47756
ServerNode
train
function ServerNode (nodeId, log, connection, options) { options = merge(options, DEFAULT_OPTIONS) BaseNode.call(this, nodeId, log, connection, options) if (this.options.fixTime) { throw new Error( 'Logux Server could not fix time. Set opts.fixTime for Client node.') } this.state = 'connecting' }
javascript
{ "resource": "" }
q47757
ClientNode
train
function ClientNode (nodeId, log, connection, options) { options = merge(options, DEFAULT_OPTIONS) BaseNode.call(this, nodeId, log, connection, options) }
javascript
{ "resource": "" }
q47758
Log
train
function Log (opts) { if (!opts) opts = { } if (typeof opts.nodeId === 'undefined') { throw new Error('Expected node ID') } if (typeof opts.store !== 'object') { throw new Error('Expected store') } if (opts.nodeId.indexOf(' ') !== -1) { throw new Error('Space is prohibited in node ID') } /...
javascript
{ "resource": "" }
q47759
add
train
function add (action, meta) { if (typeof action.type === 'undefined') { throw new Error('Expected "type" in action') } if (!meta) meta = { } var newId = false if (typeof meta.id === 'undefined') { newId = true meta.id = this.generateId() } if (typeof meta.time === 'undef...
javascript
{ "resource": "" }
q47760
generateId
train
function generateId () { var now = Date.now() if (now <= this.lastTime) { now = this.lastTime this.sequence += 1 } else { this.lastTime = now this.sequence = 0 } return now + ' ' + this.nodeId + ' ' + this.sequence }
javascript
{ "resource": "" }
q47761
each
train
function each (opts, callback) { if (!callback) { callback = opts opts = { order: 'created' } } var store = this.store return new Promise(function (resolve) { function nextPage (get) { get().then(function (page) { var result for (var i = page.entries.length...
javascript
{ "resource": "" }
q47762
WsConnection
train
function WsConnection (url, WS, opts) { this.connected = false this.emitter = new NanoEvents() if (WS) { this.WS = WS } else if (typeof WebSocket !== 'undefined') { this.WS = WebSocket } else { throw new Error('No WebSocket support') } this.url = url this.opts = opts }
javascript
{ "resource": "" }
q47763
isFirstOlder
train
function isFirstOlder (firstMeta, secondMeta) { if (firstMeta && !secondMeta) { return false } else if (!firstMeta && secondMeta) { return true } if (firstMeta.time > secondMeta.time) { return false } else if (firstMeta.time < secondMeta.time) { return true } var first = split(firstMeta....
javascript
{ "resource": "" }
q47764
LoguxError
train
function LoguxError (type, options, received) { Error.call(this, type) /** * Always equal to `LoguxError`. The best way to check error class. * @type {string} * * @example * if (error.name === 'LoguxError') { } */ this.name = 'LoguxError' /** * The error code. * @type {string} * ...
javascript
{ "resource": "" }
q47765
_getStrategyGrouping
train
function _getStrategyGrouping(_class) { return function () { var replicationParams = _.toArray(arguments) , replication = {"class": _class}; if (_class === methods.withSimpleStrategy.name) { if (typeof replicationParams[0] === "undefined") throw new Error("SimpleStrategy requires replic...
javascript
{ "resource": "" }
q47766
_getAndGrouping
train
function _getAndGrouping(type) { return function () { var boolean = _.toArray(arguments); this._statements.push({ grouping: "and", type: type, value: arguments[0] ? arguments[0] : false }); return this; }; }
javascript
{ "resource": "" }
q47767
_attachExecMethod
train
function _attachExecMethod(qb) { /** * Create the exec function for a pass through to the datastax driver. * * @param `{Object} options` optional argument passed to datastax driver upon query execution * @param `{Function} cb` => function(err, result) {} * @returns {Client|exports|module.exports} */...
javascript
{ "resource": "" }
q47768
_attachStreamMethod
train
function _attachStreamMethod(qb) { /** * Create the stream function for a pass through to the datastax driver, * all callbacks are defaulted to lodash#noop if not declared. * * @param `{Object} options` optional argument passed to datastax driver upon query execution * @param `{Object} cbs` => * { ...
javascript
{ "resource": "" }
q47769
_attachEachRowMethod
train
function _attachEachRowMethod(qb) { /** * Create the eachRow function for a pass through to the datastax driver. * * @param `{Object} options` optional argument passed to datastax driver upon query execution * @param `{Function} rowCb` => function(row) {} * @param `{Function} errorCb` => function(err) ...
javascript
{ "resource": "" }
q47770
_attachBatchMethod
train
function _attachBatchMethod(qb) { /** * * @param options * @param cassakni * @param cb * @returns {Client|exports|module.exports} */ qb.batch = function (options, cassakni, cb) { var _options , _cassakni , _cb; // options is really cassakni, cassakni is cb if (_.isArray(o...
javascript
{ "resource": "" }
q47771
startWatch
train
function startWatch() { var rp = path.join(rootPath, '/**/*.md') watcher = gulp.watch([rp, '!' + rp + '/_book/'], function() { rebuildBook(reload) }) return watcher }
javascript
{ "resource": "" }
q47772
train
function (format) { return function (data) { var el = makeElement("img", [ "image-output" ]); el.src = "data:image/" + format + ";base64," + joinText(data).replace(/\n/g, ""); return el; }; }
javascript
{ "resource": "" }
q47773
resolveExecutablePath
train
async function resolveExecutablePath (cmd) { let executablePath; try { executablePath = await fs.which(cmd); if (executablePath && await fs.exists(executablePath)) { return executablePath; } } catch (err) { if ((/not found/gi).test(err.message)) { log.debug(err); } else { log...
javascript
{ "resource": "" }
q47774
tick
train
function tick() { var moment = (new Date().getTime() - startDate)/1000; x = Math.round(150 * Math.sin(moment)); y = Math.round(150 * Math.cos(moment)); requestAnimationFrame(tick); }
javascript
{ "resource": "" }
q47775
train
function (todo) { model.remove(todo.id, function () { todos.splice(todos.indexOf(todo), 1); if (todo.completed) { completedCount--; } else { itemsLeft--; checkedAll = completedCount === todos.length; } }); }
javascript
{ "resource": "" }
q47776
train
function (query, callback) { if (!callback) { return; } var todos = data.todos; callback.call(undefined, todos.filter(function (todo) { for (var q in query) { if (query[q] !== todo[q]) { return false; } } ret...
javascript
{ "resource": "" }
q47777
train
function (updateData, callback, id) { var todos = data.todos; callback = callback || function () { }; // If an ID was actually given, find the item and update each property if (id) { for (var i = 0; i < todos.length; i++) { if (todos[i].id === id) { ...
javascript
{ "resource": "" }
q47778
train
function (id, callback) { var todos = data.todos; for (var i = 0; i < todos.length; i++) { if (todos[i].id == id) { todos.splice(i, 1); break; } } flush(); callback.call(undefined, data.todos); }
javascript
{ "resource": "" }
q47779
render
train
function render() { return h('div', [ h('input', { type: 'text', placeholder: 'What is your name?', value: yourName, oninput: handleNameInput }), h('p.output', ['Hello ' + (yourName || 'you') + '!']) ]); }
javascript
{ "resource": "" }
q47780
train
function (title, callback) { title = title || ''; callback = callback || function () { }; var newItem = { title: title.trim(), completed: false }; storage.save(newItem, callback); }
javascript
{ "resource": "" }
q47781
train
function (query, callback) { var queryType = typeof query; callback = callback || function () { }; if (queryType === 'function') { callback = query; storage.findAll(callback); } else if (queryType === 'string' || queryType === 'number') { query = parseInt(q...
javascript
{ "resource": "" }
q47782
train
function (callback) { var todos = { active: 0, completed: 0, total: 0 }; storage.findAll(function (data) { data.forEach(function (todo) { if (todo.completed) { todos.completed++; } else { todos.active++;...
javascript
{ "resource": "" }
q47783
isFileProcessable
train
function isFileProcessable(filepath) { if (options.fileFilterRegex.length === 0) { return true; } return options.fileFilterRegex.some((regex) => filepath.match(regex) !== null); }
javascript
{ "resource": "" }
q47784
session
train
async function session(ctx, next) { ctx.sessionStore = store if (ctx.session || ctx._session) { return next() } const result = await getSession(ctx) if (!result) { return next() } addCommonAPI(ctx) ctx._session = result.session // more flexible Object.definePropert...
javascript
{ "resource": "" }
q47785
deferSession
train
async function deferSession(ctx, next) { ctx.sessionStore = store // TODO: // Accessing ctx.session when it's defined is causing problems // because it has side effect. So, here we use a flag to determine // that session property is already defined. if (ctx.__isSessionDefined) { return ne...
javascript
{ "resource": "" }
q47786
getScriptData
train
function getScriptData(evt) { //Using currentTarget instead of target for Firefox 2.0's sake. Not //all old browsers will be supported, but this one was easy enough //to support and still makes sense. var node = evt.currentTarget || evt.srcElement; //Remove t...
javascript
{ "resource": "" }
q47787
completed
train
function completed() { document.removeEventListener( "DOMContentLoaded", completed, false ); window.removeEventListener( "load", completed, false ); jQuery.ready(); }
javascript
{ "resource": "" }
q47788
computePixelPositionAndBoxSizingReliable
train
function computePixelPositionAndBoxSizingReliable() { // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" + "box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;" + "position:absolute;to...
javascript
{ "resource": "" }
q47789
compareAscending
train
function compareAscending(a, b) { return baseCompareAscending(a.criteria, b.criteria) || a.index - b.index; }
javascript
{ "resource": "" }
q47790
compareMultipleAscending
train
function compareMultipleAscending(a, b) { var ac = a.criteria, bc = b.criteria, index = -1, length = ac.length; while (++index < length) { var result = baseCompareAscending(ac[index], bc[index]); if (result) { return result; } } // Fixes an `Array#sort`...
javascript
{ "resource": "" }
q47791
releaseArray
train
function releaseArray(array) { array.length = 0; if (arrayPool.length < MAX_POOL_SIZE) { arrayPool.push(array); } }
javascript
{ "resource": "" }
q47792
releaseObject
train
function releaseObject(object) { object.criteria = object.value = null; if (objectPool.length < MAX_POOL_SIZE) { objectPool.push(object); } }
javascript
{ "resource": "" }
q47793
shimTrimLeft
train
function shimTrimLeft(string, chars) { string = string == null ? '' : String(string); if (!string) { return string; } if (chars == null) { return string.slice(trimmedLeftIndex(string)) } chars = String(chars); return string.slice(charsLeftIndex(string, chars)); }
javascript
{ "resource": "" }
q47794
shimTrimRight
train
function shimTrimRight(string, chars) { string = string == null ? '' : String(string); if (!string) { return string; } if (chars == null) { return string.slice(0, trimmedRightIndex(string) + 1) } chars = String(chars); return string.slice(0, charsRightIndex(string, chars) + 1); ...
javascript
{ "resource": "" }
q47795
trimmedLeftIndex
train
function trimmedLeftIndex(string) { var index = -1, length = string.length; while (++index < length) { var c = string.charCodeAt(index); if (!((c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 || (c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 |...
javascript
{ "resource": "" }
q47796
trimmedRightIndex
train
function trimmedRightIndex(string) { var index = string.length; while (index--) { var c = string.charCodeAt(index); if (!((c <= 160 && (c >= 9 && c <= 13) || c == 32 || c == 160) || c == 5760 || c == 6158 || (c >= 8192 && (c <= 8202 || c == 8232 || c == 8233 || c == 8239 || c == 8287 || c ...
javascript
{ "resource": "" }
q47797
baseEach
train
function baseEach(collection, callback) { var index = -1, iterable = collection, length = collection ? collection.length : 0; if (typeof length == 'number') { if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); } while (++...
javascript
{ "resource": "" }
q47798
baseEachRight
train
function baseEachRight(collection, callback) { var iterable = collection, length = collection ? collection.length : 0; if (typeof length == 'number') { if (support.unindexedChars && isString(iterable)) { iterable = iterable.split(''); } while (length--) { ...
javascript
{ "resource": "" }
q47799
baseForOwn
train
function baseForOwn(object, callback) { var index = -1, props = keys(object), length = props.length; while (++index < length) { var key = props[index]; if (callback(object[key], key, object) === false) { break; } } return object; }
javascript
{ "resource": "" }