let target = '头皮环境与发质紧密相连。赋予**水润感,令精华成分充*吸收。使用感清爽舒适,***致,秀*呈现蓬松丰盈**弹力*'
let st1 = '["净含量:1kc", "头皮环境与发质紧密相连赋子头皮水润感", "令精华成分充分吸收", "使用感清爽舒适", "秀发呈现蓬松羊盈感与弹力感", "·用指腹轻轻按摩头皮使其吸收,再涂抹头发部分井加以按摩", "以头皮为重点,将头皮与头发彻底冲洗干净。", "谨防入眼", "注意事项", "入眼请立即用清水或温水冲洗,使用", "时,请避免容器内入水,全请放置于婴幼儿接触不到的地方", "本品含水杨酸", "三岁以下儿童勿用。山奇基三甲基氯化铵", "作抗静电剂使用", "原产国,日本", "请于", "年", "月之前使用", "国妆网备进宝", "202001055", "正批请印装", "生产者名称及地址:株式", "一本国东京都中央区银座", "地址:中国", "558号10号楼", "请勿使", "若使用时出现红肿、", "成分:水·山梨(糖)醇", "命基三甲基氯化铵硬脂", "醇,双内甘醉、", "李铵盐一11樱花叶提耳", "提取物酒环提", "物秦椒果皮提取物滨海", "中", "赤芝提取物,刺梨果提取物", "醇丙醇水机", "酸、腺苷、乙醇、EDTA二钠", "、硅石、丁轻甲苯、苯甲", "酸钠、苯氧乙醇、香精", "30", "28+26", "专业美发使用", "4909978934408", "19"]'
function LCS( str1 , str2 ) {
let dp=[]
let maxi,maxj
let maxlen=0
for(let i=0;i<str1.length+1;i++){
dp[i]=[]
for(let j=0;j<str2.length+1;j++){
dp[i].push(0)
}
}
for(let i=1;i<str1.length+1;i++){
for(let j=1;j<str2.length+1;j++){
if(str1[i-1]!=str2[j-1]){
dp[i][j]=0
}else{
dp[i][j]=dp[i-1][j-1]+1;
if(dp[i][j]>maxlen){
maxlen=dp[i][j]
maxi=i
maxj=j
}
}
}
}
return str2.slice(maxj-maxlen,maxj)
}
const re = LCS(st1, target)
console.log(re)
function getTextAear(source, target) {
function searchSubStr(str,subStr){
var positions = new Array();
var pos = str.indexOf(subStr);
while(pos>-1){
positions.push(pos);
pos = str.indexOf(subStr,pos+1);
}
return positions
}
const str_arr = Array.from(new Set(target.split('')))
const posts = []
str_arr.map(item => {
let post_item = searchSubStr(source,item);
if(post_item.length > 0) {
posts.push(post_item)
}
})
let total_a = []
posts.map(item => {
total_a.push(...item)
})
total_a.sort((a,b) => a-b)
const set_a = new Set(total_a)
const arr_s = Array.from(set_a)
function fn(arr, step = 5){
var result = [],
i = 0;
const list = arr.sort((a, b) => a-b);
list.forEach((item, index) => {
if (index === 0) {
result[0] = [item];
} else if (item - list[index-1] <= step ) {
result[i].push(item);
} else {
result[++i] = [item];
}
})
return result;
}
const step_a = fn(arr_s)
console.log(step_a)
}
getTextAear(st1, target)
console.log(st1.slice(32, 90))