_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q7000
checkFormat
train
function checkFormat(opt_clangOptions, opt_clangFormat, opt_gulpOptions) { var optsStr = getOptsString(opt_clangOptions); var actualClangFormat = opt_clangFormat || clangFormat; opt_gulpOptions = opt_gulpOptions || {}; var filePaths = []; var pipe = combine.obj(format(opt_clangOptions, opt_clangFormat), diff...
javascript
{ "resource": "" }
q7001
getDctWeights
train
function getDctWeights(order, N, type = 'htk') { const weights = new Float32Array(N * order); const piOverN = PI / N; const scale0 = 1 / sqrt(2); const scale = sqrt(2 / N); for (let k = 0; k < order; k++) { const s = (k === 0) ? (scale0 * scale) : scale; // const s = scale; // rta doesn't apply k=0 s...
javascript
{ "resource": "" }
q7002
transformLayer
train
function transformLayer(ctx, iCanvas, layer) { var m = layer.transform.matrix(); ctx.translate(iCanvas.width / 2, iCanvas.height / 2); ctx.transform(m[0], m[1], m[3], m[4], m[6], m[7]); if (layer.flip_h || layer.flip_v) { ctx.scale(layer.flip_h ? -1 : 1, layer.flip_v ? -1 : 1); } ctx.tr...
javascript
{ "resource": "" }
q7003
rectIntersect
train
function rectIntersect(r1, r2) { var right1 = r1.x + r1.width; var bottom1 = r1.y + r1.height; var right2 = r2.x + r2.width; var bottom2 = r2.y + r2.height; var x = Math.max(r1.x, r2.x); var y = Math.max(r1.y, r2.y); var w = Math.max(Math.min(right1, right2) - x, 0); var h = Math.max(Ma...
javascript
{ "resource": "" }
q7004
calcLayerRect
train
function calcLayerRect(iCanvas, layer) { var rect = transformRect(iCanvas, layer); rect = rectIntersect(rect, {x: 0, y: 0, width: iCanvas.width, height: iCanvas.height}); return { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.ceil(rect.width), height: Math.ceil(rect.heigh...
javascript
{ "resource": "" }
q7005
getTransformedLayerData
train
function getTransformedLayerData(iCanvas, layer, rect) { var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); canvas.width = rect.width; canvas.height = rect.height; ctx.translate(-rect.x, -rect.y); transformLayer(ctx, iCanvas, layer); ctx.drawImage(layer.img, 0,...
javascript
{ "resource": "" }
q7006
train
function (m) { if (m !== undefined) { // TODO Check for type and length this.m = m; } else { m = new Float32Array(16); m[0] = 1.0; m[1] = 0.0; m[2] = 0.0; m[3] = 0.0; m[4] = 0.0; m[5] = 1.0; m[6] = 0.0; m[7] = 0.0; m[...
javascript
{ "resource": "" }
q7007
parse
train
function parse(str) { str = str.replace(/\n/, ';'); str = str.replace(/RRULE:/, ''); str = str.replace(/DTSTART;/, 'DTSTART__SEMI__'); var pairs = str.split(';') , obj = {} ; pairs.forEach(function (pair) { pair = pair.replace(/DTSTART__SEMI__/, 'DTSTART;'); var parts = pair...
javascript
{ "resource": "" }
q7008
readDir
train
function readDir(err, files) { if (err) { internalServerError.call(this, err); } else { var dirName = decodeURIComponent( getCurrentPathName(this) ); this.output.push( "<!doctype html>", "<html>", "<head>", "<title>Index of ", dirName, "</title>", '<meta...
javascript
{ "resource": "" }
q7009
train
function(prop, prefix) { if (prop.isAbstract()) { throw 'An interface may not contain abstract definitions. ' + prefix + ' ' + prop.getName() + ' is abstract in interface ' + definition.__interface__.name + '.'; } if (prop.isFinal()) { throw 'An interface may not contain ...
javascript
{ "resource": "" }
q7010
buildSchema
train
function buildSchema(jsObj, key) { if (jsObj === undefined) return null; var type = typeOf(jsObj); switch (type) { case "array": { let schema = { type: "list", detail: buildSchema(jsObj[0]) }; key && (schema.name = key); return schema; } cas...
javascript
{ "resource": "" }
q7011
requireNJS
train
function requireNJS() { try { var module = ru(this.path); } catch(o_O) { console.error(o_O); return internalServerError.call(this, o_O); } module.onload( this.request, this.response, this ); }
javascript
{ "resource": "" }
q7012
tryReaddir
train
function tryReaddir(filepath) { var ctx = { path: filepath, files: [] }; try { ctx.files = fs.readdirSync(filepath); return ctx; } catch (err) {} try { ctx.path = path.dirname(filepath); ctx.files = fs.readdirSync(ctx.path); return ctx; } catch (err) {} return null; }
javascript
{ "resource": "" }
q7013
train
function(bool_return_object) { var obj = { __joii_type: this.__joii__.name }; for (var key in this.__joii__.metadata) { var val = this.__joii__.metadata[key]; if (val.serializable) { ...
javascript
{ "resource": "" }
q7014
merge
train
function merge(oldMap, newMap) { if (!oldMap) return newMap if (!newMap) return oldMap var oldMapConsumer = new SourceMapConsumer(oldMap) var newMapConsumer = new SourceMapConsumer(newMap) var mergedMapGenerator = new SourceMapGenerator() // iterate on new map and overwrite original position of new map wi...
javascript
{ "resource": "" }
q7015
initHannWindow
train
function initHannWindow(buffer, size, normCoefs) { let linSum = 0; let powSum = 0; const step = 2 * PI / size; for (let i = 0; i < size; i++) { const phi = i * step; const value = 0.5 - 0.5 * cos(phi); buffer[i] = value; linSum += value; powSum += value * value; } normCoefs.linear = ...
javascript
{ "resource": "" }
q7016
initWindow
train
function initWindow(name, buffer, size, normCoefs) { name = name.toLowerCase(); switch (name) { case 'hann': case 'hanning': initHannWindow(buffer, size, normCoefs); break; case 'hamming': initHammingWindow(buffer, size, normCoefs); break; case 'blackman': initBlackman...
javascript
{ "resource": "" }
q7017
plan
train
function plan(buhlmannTable, absPressure, isFreshWater, temperatureInCelcius) { this.isFreshWater = isFreshWater; this.bottomGasses = {}; this.decoGasses = {}; this.segments = []; }
javascript
{ "resource": "" }
q7018
endOfChunks
train
function endOfChunks() { this.callback = fsStat.bind(this.polpetta); if (this.boundary) { this.i = 0; this.received = {}; this.posted = []; this.join("").split(this.boundary).forEach( endOfChunks.forEach, this ); this.i || endOfChunks.done(this, this.posted.join("&")); } else { e...
javascript
{ "resource": "" }
q7019
_mmult
train
function _mmult(a, m) { m = m.slice(); var m0 = m[0]; var m1 = m[1]; var m2 = m[2]; var m3 = m[3]; var m4 = m[4]; var m5 = m[5]; var m6 = m[6]; var m7 = m[7]; var m8 = m[8]; m[0] = a[0] * m0 + a[1] * m3; m[1] = a[0] * m1 +...
javascript
{ "resource": "" }
q7020
getFn
train
function getFn (req, res, next) { var reqPath = req.params[0]; debug('getFn', 'reqPath', reqPath); stat(reqPath) .then(function (content) { if (!!content.type && content.type === 'file') { return res.sendFile(reqPath, { root: ramlPath }); } res.status(200).json(content); }...
javascript
{ "resource": "" }
q7021
abs
train
function abs(input) { if (!input) { return process.cwd(); } if (input.charAt(0) === "/") { return input; } if (input.charAt(0) === "~" && input.charAt(1) === "/") { input = ul.HOME_DIR + input.substr(1); } return path.resolve(input); }
javascript
{ "resource": "" }
q7022
inject
train
function inject(target, source) { for (var k in source.prototype) { target.prototype[k] = source.prototype[k]; } }
javascript
{ "resource": "" }
q7023
append_nested
train
function append_nested(concater,items){ concater += `\\begin{enumerate}\n`; for(var index in items){ concater += `\\item ${items[index].name}\n`; // doing append job if(items[index].subitems != undefined){ concater = append_nested(concater,items[index].subitems); } ...
javascript
{ "resource": "" }
q7024
_destroy
train
function _destroy() { var childrenLength; if (this.element) { this.element.remove(); } if (this.children !== null){ childrenLength = this.children.length; while(childrenLength > 0){ this.children[0].des...
javascript
{ "resource": "" }
q7025
destroy
train
function destroy() { if (this.__destroyed === true) { console.warn('calling on destroyed object'); } this.dispatch('beforeDestroy'); this._destroy(); this.dispatch('destroy'); this.eventListeners = null; this.__destroy...
javascript
{ "resource": "" }
q7026
render
train
function render(element, beforeElement) { if (this.__destroyed === true) { console.warn('calling on destroyed object'); } this.dispatch('beforeRender', { element : element, beforeElement : beforeElement }); if (b...
javascript
{ "resource": "" }
q7027
_grad
train
function _grad(hash, x, y, z) { var h, u, v; h = hash & 15; u = h < 8 ? x : y; v = h < 4 ? y : h === 12 || h === 14 ? x : z; return ((h & 1) === 0 ? u : -u) + ((h & 2) === 0 ? v : -v); }
javascript
{ "resource": "" }
q7028
isPreBuilt
train
function isPreBuilt(indexObj, preBuiltPath) { if (!(indexObj.isDevelopingAddon && indexObj.isDevelopingAddon()) && fs.existsSync(preBuiltPath)) { return true; } return false; }
javascript
{ "resource": "" }
q7029
dockerComposeTool
train
function dockerComposeTool(beforeFunction/* :Function */, afterFunction/* :Function */, pathToComposeFile/* : string */, { startOnlyTheseServices, envName, envVars, healthCheck, cleanUp, containerCleanUp, shouldPullImages = true, brutallyKill = false } /* :DockerComposeToolOptions */ = {})/* : s...
javascript
{ "resource": "" }
q7030
reverseBits
train
function reverseBits(x, bits) { var y = 0; for (var i = 0; i < bits; i++) { y = (y << 1) | (x & 1); x >>>= 1; } return y; }
javascript
{ "resource": "" }
q7031
selectorForm
train
function selectorForm(selector) { var str; if (selector.indexOf('[') !== -1) { var newSelector = attributeEquals(selector); newSelector = newSelector.replace('sel=', ''); // valid sass syntax var firstSelector = firstPart(selector); if (firstSelector in jquerySelectors) { ...
javascript
{ "resource": "" }
q7032
_getNewSection
train
function _getNewSection(line) { var result = new RegExp(regex.section).exec(line || ''); return result && result[1]; }
javascript
{ "resource": "" }
q7033
_isNotValidIni
train
function _isNotValidIni(line) { var check = (line || '').match(regex.bad); return !!(check && check.length > 1); }
javascript
{ "resource": "" }
q7034
getYouTubeVideoId
train
function getYouTubeVideoId(string) { if (typeof string !== 'string') { throw new TypeError('First argument must be a string.'); } var match = string.match(regex); if (match && match.length > 1) { return match[2]; } return string; }
javascript
{ "resource": "" }
q7035
link
train
function link(file, type, options) { if (file == null || file.length === 0 || typeof file !== 'string') { return null; } if (type && typeof type !== 'string') { options = type; type = undefined; } for (var i = 0; i < parsers.length; i++) { ...
javascript
{ "resource": "" }
q7036
parseLoopStatement
train
function parseLoopStatement (input) { let current = 0 let char = input[current] // parse through keys `each **foo, bar** in x`, which is everything before // the word "in" const keys = [] let key = '' while (!`${char}${lookahead(3)}`.match(/\s(in|of)\s/)) { key += char next() // if we hit a ...
javascript
{ "resource": "" }
q7037
train
function (val) { return val && typeof val === 'object' && !(val instanceof Date) && !(val instanceof ObjectId) && (!Array.isArray(val) || val.length > 0) && !(val instanceof Buffer); }
javascript
{ "resource": "" }
q7038
train
function (inData, outData, width, height, options) { options = defaultOptions(options, {strength: 1}); var a = -clamp(options.strength, 0, 1); convolve5x5(inData, outData, width, height, [ [a, a, a, a, a], [a, a, a, a, a], [a, a, 1 - a ...
javascript
{ "resource": "" }
q7039
train
function (inData, outData, width, height) { var c = 1 / 9; convolve3x3(inData, outData, width, height, [ [c, c, c], [c, c, c], [c, c, c] ]); }
javascript
{ "resource": "" }
q7040
train
function (inData, outData, width, height) { var c = 1 / 25; convolve5x5(inData, outData, width, height, [ [c, c, c, c, c], [c, c, c, c, c], [c, c, c, c, c], [c, c, c, c, c], [c, c, c, c, c] ]); }
javascript
{ "resource": "" }
q7041
train
function (inData, outData, width, height, options) { options = defaultOptions(options, {strength: 1}); var a = clamp(options.strength, 0, 1) * 5; convolve3x3(inData, outData, width, height, [ [ 0, -a, 0], [-a, 0, a], [ 0, a, 0] ...
javascript
{ "resource": "" }
q7042
train
function (inData, outData, width, height, options) { options = defaultOptions(options, {amount: 1, angle: 0}); var i, n = width * height * 4, amount = options.amount, angle = options.angle, x = Math.cos(-angle) * amount, y = Math.sin(-angle) * amount, ...
javascript
{ "resource": "" }
q7043
train
function (inData, outData, width, height) { convolve3x3(inData, outData, width, height, [ [-1, -1, -1], [-1, 8, -1], [-1, -1, -1] ], false, true, true); }
javascript
{ "resource": "" }
q7044
train
function (inData, outData, width, height) { convolve5x5(inData, outData, width, height, [ [-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1], [-1, -1, 24, -1, -1], [-1, -1, -1, -1, -1], [-1, -1, -1, -1, -1] ], ...
javascript
{ "resource": "" }
q7045
trimStringProperties
train
function trimStringProperties (obj) { if (obj !== null && typeof obj === 'object') { for ( var prop in obj ) { // if the property is an object trim it too if ( typeof obj[prop] === 'object' ) { return trimStringProperties(obj[prop]); } ...
javascript
{ "resource": "" }
q7046
preBuild
train
function preBuild(addonPath) { // Require the addon let addonToBuild = require(addonPath); // Augment it with isDevelopingAddon function. addonToBuild.isDevelopingAddon = function() { return true; } // If addon has pre-built path set in it use that else use the default path if(!addonToBuild.PREBUILT_P...
javascript
{ "resource": "" }
q7047
generator
train
function generator(seed) { // Note: the generator didn't work with negative seed values, so here we // transform our original seed into a new (positive) seed value with which we // create a new generator. if (seed < 0) { var gen = generator(Math.abs(seed)); for (var i = 0; i < 23; i += 1...
javascript
{ "resource": "" }
q7048
removeExponentByOne
train
function removeExponentByOne(node) { if (node.op === '^' && // exponent of anything Node.Type.isConstant(node.args[1]) && // to a constant node.args[1].value === '1') { // of value 1 const newNode = clone(node.args[0]); return Node.Status.nodeChanged( ChangeTypes.REM...
javascript
{ "resource": "" }
q7049
search
train
function search(simplificationFunction, node, preOrder) { let status; if (preOrder) { status = simplificationFunction(node); if (status.hasChanged()) { return status; } } if (Node.Type.isConstant(node) || Node.Type.isSymbol(node)) { return Node.Status.noChange(node); } else if (Node....
javascript
{ "resource": "" }
q7050
zipObject
train
function zipObject(keys, values) { return keys.reduce(function(object, currentValue, currentIndex) { object[currentValue] = values[currentIndex]; return object; }, {}); }
javascript
{ "resource": "" }
q7051
getAll
train
function getAll(paths) { if (paths === undefined) { return clone(state); } if (!paths instanceof Array) { throw new Error('[toystore] getAll() argument "paths" must be an array.'); } let values = paths.map(get); return zipObject(paths, values); }
javascript
{ "resource": "" }
q7052
setAll
train
function setAll(obj) { let paths = Object.keys(obj); paths.map(path => setSilent(path, obj[path])); notifyWatchersOnPaths(paths); }
javascript
{ "resource": "" }
q7053
watch
train
function watch(paths, callback, options = {}) { paths = paths === '*' ? paths : _pathsArray(paths); let id = randomString(); let defaultOptions = { async: false, priority: 0 }; options = Object.assign({}, defaultOptions, options); watchers.push({ callback, id, options, path...
javascript
{ "resource": "" }
q7054
_deepKeys
train
function _deepKeys(obj, prefix = null) { return Object.keys(obj).reduce(function(acc, key){ var value = obj[key]; if (_isObject(value)) { acc.push.apply(acc, _deepKeys(value, prefix ? prefix + '.' + key : key)); } else { acc.push(prefix ? prefix + '.' + key : key); } return acc; },...
javascript
{ "resource": "" }
q7055
nthRootConstant
train
function nthRootConstant(node) { let newNode = clone(node); const radicandNode = getRadicandNode(node); const rootNode = getRootNode(node); if (Negative.isNegative(radicandNode)) { return Node.Status.noChange(node); } else if (!Node.Type.isConstant(rootNode) || Negative.isNegative(rootNode)) { retu...
javascript
{ "resource": "" }
q7056
getRootNode
train
function getRootNode(node) { if (!Node.Type.isFunction(node, 'nthRoot')) { throw Error('Expected nthRoot'); } return node.args.length === 2 ? node.args[1] : Node.Creator.constant(2); }
javascript
{ "resource": "" }
q7057
sortNodes
train
function sortNodes(a, b) { if (Node.Type.isConstant(a) && Node.Type.isConstant(b)) { return parseFloat(a.value) - parseFloat(b.value); } else if (Node.Type.isConstant(a)) { return -1; } else if (Node.Type.isConstant(b)) { return 1; } return 0; }
javascript
{ "resource": "" }
q7058
isMultiplicationOfEqualNodes
train
function isMultiplicationOfEqualNodes(node) { if (!Node.Type.isOperator(node) || node.op !== '*') { return false; } // return if they are all equal nodes return node.args.reduce((a, b) => { return a.equals(b); }); }
javascript
{ "resource": "" }
q7059
LoginController
train
function LoginController($scope, $location, $http) { var urlParams = $location.search(); Object.defineProperties(this, { /** * The URL of the service to redirect to. * * @property service * @type String */ service: { value: urlParams.service, writ...
javascript
{ "resource": "" }
q7060
canAddLikeTermPolynomialNodes
train
function canAddLikeTermPolynomialNodes(node) { if (!Node.Type.isOperator(node) || node.op !== '+') { return false; } const args = node.args; if (!args.every(n => Node.PolynomialTerm.isPolynomialTerm(n))) { return false; } if (args.length === 1) { return false; } const polynomialTermList = a...
javascript
{ "resource": "" }
q7061
train
function (prebuild, napiVersion) { if (prebuild) { for (var i = 0; i < prebuild.length; i++) { if (prebuild[i].target === napiVersion) return true } } return false }
javascript
{ "resource": "" }
q7062
getTermName
train
function getTermName(node, op) { const polyNode = new Node.PolynomialTerm(node); // we 'name' polynomial terms by their symbol name let termName = polyNode.getSymbolName(); // when adding terms, the exponent matters too (e.g. 2x^2 + 5x^3 can't be combined) if (op === '+') { const exponent = print(polyNode...
javascript
{ "resource": "" }
q7063
sortTerms
train
function sortTerms(a, b) { if (a === b) { return 0; } // if no exponent, sort alphabetically if (a.indexOf('^') === -1) { return a < b ? -1 : 1; } // if exponent: sort by symbol, but then exponent decreasing else { const symbA = a.split('^')[0]; const expA = a.split('^')[1]; const symb...
javascript
{ "resource": "" }
q7064
getSolutionByNum
train
function getSolutionByNum(solutionSet, num) { if(solutionSet.computed.length >= num && num >= 1) { if(solutionSet.computed.length == num) { // If we select the last computed solution, we checked if we can compute more solutions. if(solutionSet.remaining !== false) { console.log("Checking for amb...
javascript
{ "resource": "" }
q7065
_createParticle
train
function _createParticle(profile, { width, height }) { const { random } = Math; const { deltaX, deltaY, deltaOpacity, radius, color, opacity } = getParticleValues(profile); return { init() { this.x = random() * width; this.y = random() * -height; this.deltaX = deltaX; this.deltaY = deltaY...
javascript
{ "resource": "" }
q7066
train
function ( query, associations ) { _.each( associations, function ( assoc ) { // if the associations is to be populated with the full records... if ( assoc.include === "record" ) query.populate( assoc.alias ); } ); return query; }
javascript
{ "resource": "" }
q7067
train
function ( req ) { // Allow customizable blacklist for params NOT to include as criteria. req.options.criteria = req.options.criteria || {}; req.options.criteria.blacklist = req.options.criteria.blacklist || [ 'limit', 'skip', 'sort', 'populate' ]; // Validate blacklist to provide a more helpful error msg. ...
javascript
{ "resource": "" }
q7068
addNumeratorsTogether
train
function addNumeratorsTogether(node) { const newNode = clone(node); newNode.args[0] = Node.Creator.constant(newNode.args[0].eval()); return Node.Status.nodeChanged( ChangeTypes.ADD_NUMERATORS, node, newNode); }
javascript
{ "resource": "" }
q7069
reduceExponentByZero
train
function reduceExponentByZero(node) { if (node.op !== '^') { return Node.Status.noChange(node); } const exponent = node.args[1]; if (Node.Type.isConstant(exponent) && exponent.value === '0') { const newNode = Node.Creator.constant(1); return Node.Status.nodeChanged( ChangeTypes.REDUCE_EXPONENT...
javascript
{ "resource": "" }
q7070
navMap_post_defaults
train
function navMap_post_defaults(map, index, parent){ replaceValues(map, { //propertyName : "forced overide value" //link : '#',//using this would disable ALL links (including links already defined in the main nav map file) }); return { depth: map.location.length, index: index, //link : '#',//this wouldn't ...
javascript
{ "resource": "" }
q7071
getWindow
train
function getWindow(node) { if (isWindow(node)) { return node; } var doc = getDocument(node); if (needsIEFallback) { // In IE 6-8, only the variable 'window' can be used to connect events (others // may be only copies). doc.parentWindow.execScript('document._parentWindow = window;', 'Javascript...
javascript
{ "resource": "" }
q7072
train
function(block, parent) { if (!block.nodes.length) return false; // line count var lines = block.nodes[block.nodes.length - 1].line - block.nodes[0].line + 1; if (lines === 1) return false; // word count of Text node values var words = 0; // number of Code nodes that are in their own lines...
javascript
{ "resource": "" }
q7073
negativeCoefficient
train
function negativeCoefficient(node) { if (NodeType.isConstant(node)) { node = NodeCreator.constant(0 - parseFloat(node.value)); } else { const numeratorValue = 0 - parseFloat(node.args[0].value); node.args[0] = NodeCreator.constant(numeratorValue); } return node; }
javascript
{ "resource": "" }
q7074
orderCoords
train
function orderCoords(coords){ if (config.coordinateOrder){ return coords; } if (coords[2]){ return [coords[1], coords[0], coords[2]]; } return coords.reverse(); }
javascript
{ "resource": "" }
q7075
multi
train
function multi(name, memberName, membercb, geom, gmlId, params={}){ var {srsName, gmlIds} = params; let multi = `<gml:${name}${attrs({srsName, 'gml:id':gmlId})}>`; multi += `<gml:${memberName}>`; geom.forEach(function(member, i){ let _gmlId = member.id || (gmlIds || [])[i] || ''; if (name == 'MultiGeome...
javascript
{ "resource": "" }
q7076
makeConverter
train
function makeConverter(obj) { return Object.entries(obj).map(([type, converter]) => { return {[type[0].toUpperCase() + type.slice(1)]: converter}; }).reduce((a, b) => Object.assign(a, b), {}); }
javascript
{ "resource": "" }
q7077
performTermOperationOnEquation
train
function performTermOperationOnEquation(equation, op, term, changeType) { const oldEquation = equation.clone(); const leftTerm = clone(term); const rightTerm = clone(term); const leftNode = performTermOperationOnExpression( equation.leftNode, op, leftTerm); const rightNode = performTermOperationOnExpress...
javascript
{ "resource": "" }
q7078
performTermOperationOnExpression
train
function performTermOperationOnExpression(expression, op, term) { const node = (Node.Type.isOperator(expression) ? Node.Creator.parenthesis(expression) : expression); term.changeGroup = 1; const newNode = Node.Creator.operator(op, [node, term]); return newNode; }
javascript
{ "resource": "" }
q7079
canMultiplyLikeTermPolynomialNodes
train
function canMultiplyLikeTermPolynomialNodes(node) { if (!Node.Type.isOperator(node) || node.op !== '*') { return false; } const args = node.args; if (!args.every(n => Node.PolynomialTerm.isPolynomialTerm(n))) { return false; } if (args.length === 1) { return false; } const polynomialTermLis...
javascript
{ "resource": "" }
q7080
simulatedUserInput
train
function simulatedUserInput(numArray) { // pause + first one // forEach after the first: outer + inner const rest$ = numOrArray => { if (!numOrArray.length) return after(pause, () => numOrArray) let rest = after(pause, () => numOrArray[0]) for (let i = 1; i < numOrArray.length; i++) { ...
javascript
{ "resource": "" }
q7081
getUserInputFromStdin
train
function getUserInputFromStdin() { // set up stdin const keypress = require("keypress") keypress(process.stdin) process.stdin.setRawMode(true) process.stdin.resume() // A Subject is something that you can push values at, and // it can be subscribed to as an Observable of those values co...
javascript
{ "resource": "" }
q7082
getTitleMap
train
function getTitleMap(startMap, userSearchTerm, isRecursive) { var returnValue = false; var found = false; var isRecursive = defaultTo(isRecursive, true); function iterator(map, searchTerm){ for(var i = 0; i < map.length; i++) { var item = map[i]; //removes any html in the strings before searching f...
javascript
{ "resource": "" }
q7083
checkSearchTerm
train
function checkSearchTerm(searchTerm){ if (!is_string(searchTerm) && !is_numeric(searchTerm)){ console.log('\nError: This must be either a string or an interval:\n', searchTerm, ' \n'); return false; } else { return true; } }
javascript
{ "resource": "" }
q7084
getSpecificMap
train
function getSpecificMap(map, array){ var returnMap; var arrayCopy = array.splice(0); //if first item in array is "current" or "subnav" it makes the function a bit more efficient //it restricts any title searches to just offspring of the current page if (array[0] === 'current' || array[0] === 'subnav'){ ar...
javascript
{ "resource": "" }
q7085
getNavMap
train
function getNavMap(navMap, searchTerm, portion){ let returnMap = navMap; if (!isset(searchTerm) || is_array(searchTerm) && searchTerm.length === 0){ //if the search term is an empty array, it will return the full nav map (excluding ROOT) return returnMap; } //code for when an array is given (filters r...
javascript
{ "resource": "" }
q7086
castInterpolate
train
function castInterpolate(template, replacements, options) { var matches = template.match(regExp); var placeholder; var not; if (matches) { placeholder = matches[1]; // Check if exists first if (mout.object.has(replacements, placeholder)) { return mout.object.get(rep...
javascript
{ "resource": "" }
q7087
reduceMultiplicationByZero
train
function reduceMultiplicationByZero(node) { if (node.op !== '*') { return Node.Status.noChange(node); } const zeroIndex = node.args.findIndex(arg => { if (Node.Type.isConstant(arg) && arg.value === '0') { return true; } if (Node.PolynomialTerm.isPolynomialTerm(arg)) { const polyTerm = ...
javascript
{ "resource": "" }
q7088
speakIt
train
function speakIt({ action }) { const { toSpeak } = action.payload // Remember: unlike Promises, which share a similar construction, // the observable function is not run until the Observable recieves // a subscribe() call. return new Observable(observer => { try { const say = require(...
javascript
{ "resource": "" }
q7089
removeUnnecessaryParens
train
function removeUnnecessaryParens(node, rootNode=false) { // Parens that wrap everything are redundant. // NOTE: removeUnnecessaryParensSearch recursively removes parens that aren't // needed, while this step only applies to the very top level expression. // e.g. (2 + 3) * 4 can't become 2 + 3 * 4, but if (2 + 3...
javascript
{ "resource": "" }
q7090
removeUnnecessaryParensInOperatorNode
train
function removeUnnecessaryParensInOperatorNode(node) { node.args.forEach((child, i) => { node.args[i] = removeUnnecessaryParensSearch(child); }); // Sometimes, parens are around expressions that have been simplified // all they can be. If that expression is part of an addition or subtraction // operation...
javascript
{ "resource": "" }
q7091
removeUnnecessaryParensInFunctionNode
train
function removeUnnecessaryParensInFunctionNode(node) { node.args.forEach((child, i) => { if (Node.Type.isParenthesis(child)) { child = child.content; } node.args[i] = removeUnnecessaryParensSearch(child); }); return node; }
javascript
{ "resource": "" }
q7092
canCollectOrCombine
train
function canCollectOrCombine(node) { return LikeTermCollector.canCollectLikeTerms(node) || checks.resolvesToConstant(node) || checks.canSimplifyPolynomialTerms(node); }
javascript
{ "resource": "" }
q7093
Invoker
train
function Invoker(zk, opt) { if (!(this instanceof Invoker)) return new Invoker(zk, opt); var option = opt || {}; this._path = option.path; this._dubbo = option.dubbo; this._version = option.version; this._timeout = option.timeout; this._poolMax = option.poolMax; this._poolMin = option.poolMin; this....
javascript
{ "resource": "" }
q7094
_expandNestedPaths
train
function _expandNestedPaths(paths) { var expandedPaths = []; _pathsArray(paths).forEach(function (p) { if (p.indexOf('.') !== -1) { var pathsWithRoots = p.split('.').map(function (value, index, array) { return array.slice(0, index + 1).join('.'); }); expandedPaths = expandedPaths.con...
javascript
{ "resource": "" }
q7095
train
function(remoteID, keycode) { if (!config.opened && config.pinNumber !== null) this.open(config.pinNumber); if (!config.opened) throw new Error('Trying to write with no pins opened'); debugMsg("sendButton: remoteID: " + remoteID + " keycode: " + keycode); // how many times to transmit a command fo...
javascript
{ "resource": "" }
q7096
removeMultiplicationByOne
train
function removeMultiplicationByOne(node) { if (node.op !== '*') { return Node.Status.noChange(node); } const oneIndex = node.args.findIndex(arg => { return Node.Type.isConstant(arg) && arg.value === '1'; }); if (oneIndex >= 0) { let newNode = clone(node); // remove the 1 node newNode.args....
javascript
{ "resource": "" }
q7097
maybeFlattenPolynomialTerm
train
function maybeFlattenPolynomialTerm(node) { // We recurse on the left side of the tree to find operands so far const operands = getOperands(node.args[0], '*'); // If the last operand (so far) under * was a constant, then it's a // polynomial term. // e.g. 2*5*6x creates a tree where the top node is implicit ...
javascript
{ "resource": "" }
q7098
flattenDivision
train
function flattenDivision(node) { // We recurse on the left side of the tree to find operands so far // Flattening division is always considered part of a bigger picture // of multiplication, so we get operands with '*' let operands = getOperands(node.args[0], '*'); if (operands.length === 1) { node.args[...
javascript
{ "resource": "" }
q7099
removeAdditionOfZero
train
function removeAdditionOfZero(node) { if (node.op !== '+') { return Node.Status.noChange(node); } const zeroIndex = node.args.findIndex(arg => { return Node.Type.isConstant(arg) && arg.value === '0'; }); let newNode = clone(node); if (zeroIndex >= 0) { // remove the 0 node newNode.args.splic...
javascript
{ "resource": "" }