Best JavaScript code snippet using redwood
figureArea.js
Source:figureArea.js
1/*2 2021. 12. 183 [íë¡ê·¸ëë° ìì]4 1) ìì¸ì²ë¦¬ -> ìì¸ ì ë©ìì§ì¶ë ¥ & ì¢
ë£5 2) ì
ë ¥í ë´ì©ì ë°íì¼ë¡ ìë§ì figure를 구í¨. getFigure6 3) figuredì ë§ì¶° ìë§ì í¨ì í¸ì¶. getRect, getCircle ...7 4) ì¤íë figure를 ë¡ê·¸ ì ì¥. saveExecution8 [ìì¸ì²ë¦¬]9 1) ëí ì´ë¦ì´ ì ííì§ ìì ë10 2) ê¸¸ì´ ê°ì ì
ë ¥íì§ ììì ë11 3) ê¸¸ì´ ê°ì´ ìì°ìê° ìë ë12 [ë
¸í¸]13 1) 구조 ë³ê²½14 - ì´ì íì´ë ì¬ì©ì ì
ë ¥ì´ circleì¼ ê²½ì°, getCircle를 í¸ì¶íê³ , getCircle ììì 매ê°ë³ìì ë°ë¼ getCircles를 ë í¸ì¶íë 구조ì´ë¤.15 - ì´ë´ ê²½ì°, ë©ì¸ í¨ì getAreaë§ ë³´ê³ ë getCirclesê¹ì§ ê°ë ë¡ì§ì ì ííê² ì´í´í기 ì´ë µë¤.16 - ì¤ê°ì ì¬ì©ì ì
ë ¥ì ë§ì¶° ì íí figure를 구íë ê³¼ì ì ì¶ê°íë¤. ê·¸ë¦¬ê³ ê·¸ figureì ë§ì¶° íìí í¨ì를 ë°ë¡ ì¶ë ¥í ì ìëë¡ ìì íë¤.17 - ë©ì¸ í¨ì getAreaë§ ë´ë ì ì²´ 구조를 ë ì íì
í ì ìëë¡ ë³ê²½íë¤.18 2) ìì¸ì²ë¦¬ ì¶ê°19 - ê¸°ì¡´ë³´ë¤ ë ëì ë²ìì ìì¸ì²ë¦¬ë¥¼ ì¶ê°íë¤.20 3) switch문 -> if문 ë³ê²½21 - ê°ì¸ì ì¼ë¡ ifë¬¸ì´ ë ê°ê²°íê³ ê°ë
ì±ì´ ë°ì´ë ê² ê°ìì ë³ê²½íë¤.22 - 문 ììì í¹ë³í ë¡ì§ì´ ìëê² ìëë¼ í ì¤ì§ë¦¬ ê°ë¨í ìì´ë¼ {}, break, case ë±ì ë ì¨ì¼íë switchë¬¸ì´ ë ë³µì¡í ê² ê°ë¤.23 - if문ì¼ë¡ í ì¤ë¡ ê°ë¨íê² ì²ë¦¬ê° ê°ë¥íë¤.24 4)25 - Math.PI26 - Math.pow(ì«ì, ì ê³±)27*/28const logs = [];29const getArea = (figureInput, ...values) => {30 if (!isValidArgs(figureInput, values)) return;31 const figure = getFigure(figureInput, values);32 let area;33 if (figure === 'rect') area = getRect(...values);34 if (figure === 'trapezoid') area = getTrapezoid(...values);35 if (figure === 'circle') area = getCircle(...values);36 if (figure === 'circles') area = getCircles(...values);37 saveExecution(figure);38 console.log(area);39};40const getFigure = (figure, values) => {41 if (figure === 'circle' && values.length > 1) return 'circles';42 return figure;43};44const getRect = (length1, length2) => length1 * length2;45const getTrapezoid = (top, bottom, height) => ((top + bottom) * height) / 2;46const getCircle = (radius) => Math.pow(radius, 2) * Math.PI;47const getCircles = (firstRadius, lastRadius) => {48 let total = 0;49 for (let i = firstRadius; i <= lastRadius; i++) {50 total += Math.pow(i, 2) * Math.PI;51 }52 return total;53};54const saveExecution = (figure) => logs.push(figure);55const printExecutionSequence = () => console.log(`ê³ì°ìíìì: ${logs}`);56const isValidArgs = (figure, values) => {57 const figures = ['circle', 'rect', 'trapezoid'];58 if (!figures.includes(figure)) {59 console.log('ëíì ì´ë¦ì ë°ë¥´ê² ì
ë ¥íì¸ì.');60 return false;61 }62 if (!values.length) {63 console.log('ê¸¸ì´ ê°ì ì
ë ¥íì¸ì.');64 return false;65 }66 if (67 values.some((value) => value <= 0) ||68 values.some((value) => value % 1 !== 0)69 ) {70 console.log('ê¸¸ì´ ê°ì ìì°ì를 ì
ë ¥íì¸ì.');71 return false;72 }73 if (figure === 'circle' && values[0] > values[1]) {74 console.log('ìì ë°ì§ë¦ì´ ì¢
ë£ ë°ì§ë¦ë³´ë¤ í´ ì ììµëë¤.');75 return false;76 }77 return true;78};79getArea('rect', 10, 10);80getArea('trapezoid', 10, 15, 12);81getArea('circle', 10);82getArea('circle', 1, 10);...
workflow.js
Source:workflow.js
1// con-rest2// Version: 0.0.13//4// Author: Andy Tang5// Fork me on Github: https://github.com/EnoF/con-rest6(function workflowScope(mongoose, queue, api, connector, Workflow, WorkflowExecution, Execution, APICall) {7 'use strict';8 var helper = require('./serverHelper');9 function getWorkflows(req, res) {10 return helper.getAll(Workflow, req, res);11 }12 function getWorkflowById(req, res) {13 return Workflow.findById(req.params.id)14 .populate('calls')15 .exec()16 .then(function returnWorkflow(workflow) {17 if (!!workflow) {18 res.send(workflow);19 } else {20 res.status(404).send('not found');21 }22 return workflow;23 }, helper.sendAndResolve);24 }25 function deleteWorkflow(req, res) {26 return helper.deleteById(Workflow, req, res);27 }28 function registerWorkflow(req, res) {29 return helper.createAndReturnId(Workflow, req, res);30 }31 function saveWorkflow(req, res) {32 return helper.updateById(Workflow, req, res);33 }34 function getSorted(arr, sortArr) {35 var sorted = [];36 for (var i = 0; i < sortArr.length; i++) {37 var id = sortArr[i];38 var filtered = filterOnId(arr, id);39 sorted.push(filtered[0]);40 }41 return sorted;42 }43 function filterOnId(arr, id) {44 return arr.filter(function filterOnId(obj) {45 return String(obj._id) === String(id);46 });47 }48 function executeWorkflowById(req, res) {49 var id = mongoose.Types.ObjectId(req.params.id);50 var workflow = null;51 var callIndex = 0;52 var callResults = {};53 return Workflow.findById(id)54 .populate('connectors.mapper')55 .exec()56 .then(function getCalls(retrievedWorkflow) {57 workflow = retrievedWorkflow;58 return APICall.find({59 _id: {60 $in: workflow.calls61 }62 }).populate('files.file').exec();63 })64 .then(function orderCalls(retrievedCalls) {65 return getSorted(retrievedCalls, workflow.calls);66 })67 .then(function executeCalls(retrievedCalls) {68 var apiCallQueue = queue();69 for (var i = 0; i < retrievedCalls.length; i++) {70 var call = retrievedCalls[i];71 apiCallQueue = apiCallQueue72 .then(connector.executeConnector(workflow, call, callResults))73 .then(api.executeAPICall)74 .then(registerAPICallExecution(queue, callIndex, callResults));75 }76 return apiCallQueue;77 })78 .then(function displayResults() {79 var results = [];80 return saveExecutions(workflow, callResults, results)81 .then(function saveExecution() {82 return saveWorkflowExecution(workflow, results);83 })84 .then(function(workflowExecution) {85 res.send(workflowExecution);86 });87 }, function error(err) {88 if (res.status) {89 console.log(err.toString());90 res.status(500).send(err.toString());91 }92 throw err;93 });94 }95 function saveExecutions(workflow, callResults, results) {96 var executionSaving = queue();97 for (var i in callResults) {98 var result = callResults[i];99 executionSaving = executionSaving100 .then(saveExecution(workflow, result))101 .then(pushResult(results));102 }103 return executionSaving;104 }105 function pushResult(results) {106 return function(entry) {107 results.push(entry);108 };109 }110 function saveWorkflowExecution(workflow, results) {111 var executionIds = results.map(function(execution) {112 return execution._id;113 });114 return WorkflowExecution.create({115 workflow: workflow._id,116 executedAt: new Date(),117 executions: executionIds118 });119 }120 function saveExecution(workflow, result) {121 return function saveExecution() {122 return Execution.create({123 workflow: workflow._id,124 apiCall: result.apiCall._id,125 url: result.url,126 statusCode: result.statusCode,127 response: result.response,128 headers: result.headers,129 type: result.type,130 data: result.data131 });132 };133 }134 function registerAPICallExecution(queue, callIndex, callResults) {135 return function registeredAPICall(data) {136 data.index = callIndex++;137 callResults[data.apiCall.id] = data;138 return data;139 };140 }141 module.exports = {142 deleteWorkflow: deleteWorkflow,143 getWorkflows: getWorkflows,144 getWorkflowById: getWorkflowById,145 registerWorkflow: registerWorkflow,146 saveWorkflow: saveWorkflow,147 executeWorkflowById: executeWorkflowById148 };149}(150 require('mongoose'),151 require('q'),152 require('./api.js'),153 require('./connector.js'),154 require('./resources/Workflow'),155 require('./resources/WorkflowExecution'),156 require('./resources/Execution'),157 require('./resources/APICall')...
main.ts
Source:main.ts
1import {Winston} from './common/winston';2import {environment} from './environments';3import {CrawlerController} from './controller/crawler.controller';4import {AdvogadoModel} from './model/advogado.model';5import {SalvaJsonController} from './controller/salva-json.controller';6import {SalvaCsvController} from './controller/salva-csv.controller';7const winston = new Winston(environment.paths.logDir, 'execucao.log');8const crawler = new CrawlerController(environment.crawler.oabInicial);9const salvaJSON = new SalvaJsonController();10const salvaCSV = new SalvaCsvController();11winston.saveExecution('InÃcio da Execução');12crawler.capturaAdvogados().then((advogados: AdvogadoModel[]) => {13 salvaJSON.salvaJson('advogados.json', advogados);14 salvaCSV.salvaCSV('advogados.csv', advogados);15 advogados.forEach(item => {16 item.foto = null;17 });18 salvaJSON.salvaJson('advogados_sem_foto.json', advogados);19 salvaCSV.salvaCSV('advogados_sem_foto.csv', advogados);20 winston.saveExecution('Fim da Execução');21}).catch(e => {22 winston.saveExecution(`Erro de execução: ${e.message}`);...
Using AI Code Generation
1var redwood = require('redwood');2redwood.SaveExecution("test", "test", "test", "test", "test", function (err, data) {3 if (err) {4 }5 else {6 }7});
Using AI Code Generation
1var redwood = require('redwood');2redwood.SaveExecution('test.js', 'hello world', 'test', function(err, result) {3 if (err) {4 console.log(err);5 }6 else {7 console.log(result);8 }9});10var redwood = require('redwood');11redwood.GetExecution('test.js', 'test', function(err, result) {12 if (err) {13 console.log(err);14 }15 else {16 console.log(result);17 }18});19var redwood = require('redwood');20redwood.GetExecution('test.js', 'test', function(err, result) {21 if (err) {22 console.log(err);23 }24 else {25 console.log(result);26 }27});28var redwood = require('redwood');29redwood.GetExecution('test.js', 'test', function(err, result) {30 if (err) {31 console.log(err);32 }33 else {34 console.log(result);35 }36});37var redwood = require('redwood');38redwood.GetExecution('test.js', 'test', function(err, result) {39 if (err) {40 console.log(err);41 }42 else {43 console.log(result);44 }45});46var redwood = require('redwood');47redwood.GetExecution('test.js', 'test', function(err, result) {48 if (err) {49 console.log(err);50 }51 else {52 console.log(result);53 }54});55var redwood = require('redwood');56redwood.GetExecution('test.js', 'test', function(err, result) {57 if (err) {58 console.log(err);59 }60 else {61 console.log(result);62 }63});64var redwood = require('redwood');65redwood.GetExecution('test.js', 'test', function(err, result) {66 if (err) {67 console.log(err);68 }69 else {70 console.log(result);71 }72});73var redwood = require('
Using AI Code Generation
1var redwood = require('redwoodjs');2var execution = redwood.SaveExecution('test', 'test', 'test');3console.log(execution);4var redwood = require('redwoodjs');5var execution = redwood.SaveExecution('test2', 'test2', 'test2');6console.log(execution);7var redwood = require('redwoodjs');8var execution = redwood.SaveExecution('test3', 'test3', 'test3');9console.log(execution);10var redwood = require('redwoodjs');11var execution = redwood.SaveExecution('test4', 'test4', 'test4');12console.log(execution);13var redwood = require('redwoodjs');14var execution = redwood.SaveExecution('test5', 'test5', 'test5');15console.log(execution);16var redwood = require('redwoodjs');17var execution = redwood.SaveExecution('test6', 'test6', 'test6');18console.log(execution);19var redwood = require('redwoodjs');20var execution = redwood.SaveExecution('test7', 'test7', 'test7');21console.log(execution);22var redwood = require('redwoodjs');23var execution = redwood.SaveExecution('test8', 'test8', 'test8');24console.log(execution);25var redwood = require('redwoodjs');26var execution = redwood.SaveExecution('test9', 'test9', 'test9');27console.log(execution);28var redwood = require('redwoodjs');29var execution = redwood.SaveExecution('test10', 'test10', 'test10');30console.log(execution
Using AI Code Generation
1var redwood = require('redwood');2var saveExec = redwood.SaveExecution;3var obj = {name: 'Jasmine', age: 24};4var obj2 = {name: 'Sara', age: 25};5saveExec('obj', obj);6saveExec('obj2', obj2);7var obj3 = {name: 'Alex', age: 26};8saveExec('obj3', obj3);9var redwood = require('redwood');10var getExec = redwood.GetExecution;11var obj = getExec('obj');12var obj2 = getExec('obj2');13var obj3 = getExec('obj3');14console.log(obj);15console.log(obj2);16console.log(obj3);
Using AI Code Generation
1var redwood = require('redwood');2var rw = new redwood.Redwood();3var rwConfig = rw.config();4rwConfig.saveExecution('test.js', 'test');5var redwood = require('redwood');6var rw = new redwood.Redwood();7var rwConfig = rw.config();8rwConfig.saveExecution('test.js', 'test');9var redwood = require('redwood');10var rw = new redwood.Redwood();11var rwConfig = rw.config();12rwConfig.saveExecution('test.js', 'test');13var redwood = require('redwood');14var rw = new redwood.Redwood();15var rwConfig = rw.config();16rwConfig.saveExecution('test.js', 'test');17var redwood = require('redwood');18var rw = new redwood.Redwood();19var rwConfig = rw.config();20rwConfig.saveExecution('test.js', 'test');21var redwood = require('redwood');22var rw = new redwood.Redwood();23var rwConfig = rw.config();24rwConfig.saveExecution('test.js', 'test');25var redwood = require('redwood');26var rw = new redwood.Redwood();27var rwConfig = rw.config();28rwConfig.saveExecution('test.js', 'test');29var redwood = require('redwood');30var rw = new redwood.Redwood();31var rwConfig = rw.config();32rwConfig.saveExecution('test.js', 'test');33var redwood = require('redwood');34var rw = new redwood.Redwood();35var rwConfig = rw.config();36rwConfig.saveExecution('test.js', 'test');37var redwood = require('redwood');38var rw = new redwood.Redwood();39var rwConfig = rw.config();40rwConfig.saveExecution('test.js', 'test');41var redwood = require('redwood');42var rw = new redwood.Redwood();43var rwConfig = rw.config();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!