AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

right

简介

right方法是FuzzySet类中的一个实例方法,用于根据传入的前缀查找数据集中匹配该前缀的元素,并返回以该前缀结尾的最长元素。

语法

FuzzySet.prototype.right(prefix, maxDistance)

参数

  • prefix: 需要查找的前缀,类型为字符串。
  • maxDistance: 可选参数,可指定查找时允许的最大编辑距离,默认值为0

返回值

如果匹配到了以该前缀结尾的元素,则返回该元素;否则返回null

示例

const fuzzyset = new FuzzySet(['apple', 'banana', 'cherry', 'durian']);

console.log(fuzzyset.right('a')); // 'banana'
console.log(fuzzyset.right('ap')); // 'apple'
console.log(fuzzyset.right('d')); // 'durian'
console.log(fuzzyset.right('z')); // null

console.log(fuzzyset.right('a', 1)); // 'apple'
console.log(fuzzyset.right('chey', 1)); // 'cherry'
console.log(fuzzyset.right('durioi', 2)); // 'durian'
console.log(fuzzyset.right('ban', 2)); // 'banana'
console.log(fuzzyset.right('z', 1)); // null

参考链接