8000 GitHub - 1045290202/kmp: 扩展kmp算法实现查找字符串或数组在原始字符串或数组中的位置
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

1045290202/kmp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KMP

扩展kmp算法实现查找字符串或数组在原始字符串或数组中的位置。

使用

npm i kmp-search
import { findIndex } from "kmp-search";

const stringIndex: number = findIndex("hello world", "world");
console.log(stringIndex); // 6

const numberArrayIndex: number = findIndex([1, 2, 3, 4, 5], [3, 4]);
console.log(numberArrayIndex); // 2

const objectArrayIndex: number = findIndex(
    [{ var1: 1 }, { var1: 2 }, { var1: 3, var2: "" }],
    [{ var1: 2 }, { var1: 3 }],
    (a, b) => a.var1 === b.var1,
);
console.log(objectArrayIndex); // 1,使用了自定义比较函数

const notFindIndex: number = findIndex([1, 2, 3], [2, 3, 4]);
console.log(notFindIndex); // -1,没有找到

About

扩展kmp算法实现查找字符串或数组在原始字符串或数组中的位置

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published
0