MCPcopy Create free account
hub / github.com/codecombat/codecombat / fuzzyMatch

Function fuzzyMatch

app/lib/code-to-blocks.js:4–32  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

2const { javascriptGenerator } = require('blockly/javascript')
3
4function fuzzyMatch (a, b) {
5 if (a.type !== b.type) return false
6 switch (a.type) {
7 case 'Identifier':
8 return a.name === b.name
9 case 'CallExpression':
10 if (!fuzzyMatch(a.callee, b.callee)) return false
11 return true
12 case 'MemberExpression':
13 return fuzzyMatch(a.object, b.object) && fuzzyMatch(a.property, b.property) && a.computed === b.computed
14 case 'NumericLiteral':
15 case 'StringLiteral':
16 case 'BooleanLiteral':
17 return true
18 case 'ArrayExpression':
19 return (a.elements.length === 0) === (b.elements.length === 0)
20 case 'BreakStatement':
21 case 'ContinueStatement':
22 return true
23 case 'WhileStatement':
24 case 'ForStatement':
25 case 'ConditionalExpression':
26 return true
27 case 'IfStatement':
28 return true
29 default:
30 throw new Error(`Don't know how to fuzzy compare ${a.type}`)
31 }
32}
33
34function findOne (array, pred, why = 'Expected exactly one match') {
35 const matches = array.filter(pred)

Callers 12

ConvertNumericLiteralMethod · 0.85
ConvertStringLiteralMethod · 0.85
ConvertBooleanLiteralMethod · 0.85
ConvertBreakStatementMethod · 0.85
ConvertWhileStatementMethod · 0.85
ConvertForStatementMethod · 0.85
ConvertCallExpressionMethod · 0.85
ConvertIdentifierMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected