当前位置: 首页 > news >正文

wordpress怎么安装访问推广seo网站

wordpress怎么安装访问,推广seo网站,有哪些熟悉的网站是jsp做的,开一个做网站的工作室目录 一、基础函数 二、实际应用 2.1、根据id找到对应的value值(找第一个) 2.2、根据id找到对应的value值(找所有) 2.3、不重复的升序数组找数字(二分查找) 2.4、重复的无序数组找数字(统计个数) 2.5、将数组整理为树结构(省市区为例) 为什么要积累呢?因为面…

目录

一、基础函数

二、实际应用

2.1、根据id找到对应的value值(找第一个)

2.2、根据id找到对应的value值(找所有)

2.3、不重复的升序数组找数字(二分查找)

2.4、重复的无序数组找数字(统计个数)

2.5、将数组整理为树结构(省市区为例)

为什么要积累呢?因为面试的时候总是问:在开发过程中有没有封装过一些hooks?

一、基础函数

先准备一个textHook.ts文件,在里面定义相关函数,并抛出

export function sayHello(name: string): string {return `Hello,${name}`;
}
export function add(a: number, b: number): number {return a + b;
}

在HTML文件里具体应用:

<template><p>{{ helloMessage }}</p> <!-- 结果为:Hello,Vue3+ts --><p>{{ sum }}</p> <!-- 结果为:8 -->
</template>
<script lang="ts" setup>
import { sayHello, add } from "@/hooks/textHook";
const helloMessage = ref<string>(sayHello("Vue3+ts"));
const sum = ref<number>(add(5, 3));
</script>

二、实际应用

2.1、根据id找到对应的value值(找第一个)

页面应用如下:

<template><!-- 参数:(任意值,它在该数组中对应的属性名,数组,要找的属性名) --><!-- 返回: 根据该值要找的属性名的值--><p>{{ findKey(2, "value", emergencyLevel, "desc") }}</p><!-- 结果为:紧急 -->
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import { findKey } from "@/hooks/textHook";
const emergencyLevel = reactive([{name: "VERY_URGENT",desc: "非常紧急",value: 3,},{name: "URGENT",desc: "紧急",value: 2,},{name: "GENERAL",desc: "一般",value: 1,},
]);
</script>

hooks.ts如下:

interface ItemWithValue {[key: string]: any;
}
export function findKey<T extends ItemWithValue>(inputValue: number | string,inputKey: string,arrs: T[],targetKey: string
) {const result = arrs.find((item) => item[inputKey] === inputValue);return result ? result[targetKey] : null;
}

2.2、根据id找到对应的value值(找所有)

假设数组长这样:

    <!-- 参数:(任意值,它在该数组中对应的属性名,数组,要找的属性名) --><!-- 返回: 根据该值要找的属性名的所有值--><p>{{ findMutiKey(2, "id", arrs, "title").toString() }}</p><!-- 结果为:Item 2,Item 2——Cpoyvalue -->
const arrs = reactive([{ id: 1, title: "title 1" },{ id: 2, title: "title 2" },{ id: 2, title: "title 2——Cpoyvalue" },{ id: 3, title: "title 3" },
]);

hook.ts如下:

export function findMutiKey<T extends ItemWithValue>(inputValue: number | string,inputKey: string,arrs: T[],targetKey: string
): T[] {// 使用filter找到所有匹配的对象const result = arrs.filter((item) => item[inputKey] === inputValue);// 从匹配的对象中提取出对应键的值return result ? result.map((result) => result[targetKey]) : [];
}

一般来说会直接在页面里写个方法,比如下面:

<span>{{ getEmergencyDescription(detail.urgent_level) }}</span>const getEmergencyDescription = (level: number) => {const emergency = emergencyLevel.find((item) => item.value === level);return emergency ? emergency.desc : "";
};

但是这样只能给这一种情况使用,还是要封装大众化函数,可以适配各种情况。

2.3、不重复的升序数组找数字(二分查找)

  <!-- 参数:(数组,指定数字) --><!-- 返回:找到返回下标,找不到返回-1 --><p>{{ findAsceOrderIndex(indexArrs, 12) }}</p><p>{{ findAsceOrderIndex(indexArrs, 999) }}</p>const indexArrs = ref([1, 5, 8, 12, 34, 89, 137]);

hook.ts如下:

export function findAsceOrderIndex(arrs: number[], target: number): number | null {let left = 0;let right = arrs.length - 1;while (left < right) {const mid = Math.floor((left + right) / 2);if (arrs[mid] === target) {return mid; //直接找到} else if (arrs[mid] < target) {left = mid + 1; //搜右半部分} else {right = mid - 1; //搜左半部分}}return null;
}

时间复杂度是 O(log⁡n)【执行时间与输入数据规模的对数成正比】,非常适合处理有序数组。

这样比直接遍历整个数组节省了至少一半的性能。

2.4、重复的无序数组找数字(统计个数)

  <p>{{ findDisorderLength(indexArrs, 9) }}</p><!-- 结果是:2 -->
const indexArrs = ref([1, 9, 3, 55, 7, 11, 50, 9, 11]);export function findDisorderLength(arrs: number[], target: number): number {const result = arrs.map((item, index) => (item === target ? index : -1)).filter((index) => index !== -1);// 第一步map后剩下[ -1, 1, -1, -1, -1, -1, -1, 7, -1 ]// 第二步filter后剩下[ 1,7 ]return result ? result.length : 0;
}

2.5、将数组整理为树结构(省市区为例)

  <p>{{ buildTree(regionList,"parentCode", "code") }}</p>export function buildTree<T extends { [key: string]: any }>(list: T[],parentKey: keyof T,key: keyof T
): T[] {const map = new Map<T[keyof T], T>();const tree: T[] = [];// 构建一个以parentCode为键的maplist.forEach((item) => {map.set(item[key], { ...item, children: [] });});list.forEach((item) => {const child = map.get(item[key]);if (child && item[parentKey] !== undefined && item[parentKey] !== null) {const parent = map.get(item[parentKey]);// 有父地区:将当前地区添加到父地区的children里if (parent) {parent.children?.push(child);}} else if (child) {tree.push(child);//顶层地区}});return tree;
}

备注:

操作符keyof:用于获取一个类型的所有键(属性名)的联合类型

未完待续......


文章转载自:
http://beastie.c7507.cn
http://hotch.c7507.cn
http://sigh.c7507.cn
http://gastronom.c7507.cn
http://transvalue.c7507.cn
http://dor.c7507.cn
http://reelection.c7507.cn
http://rearview.c7507.cn
http://underwater.c7507.cn
http://tarentism.c7507.cn
http://biotic.c7507.cn
http://cyton.c7507.cn
http://coati.c7507.cn
http://prepuce.c7507.cn
http://herbert.c7507.cn
http://colone.c7507.cn
http://metairie.c7507.cn
http://aristotelean.c7507.cn
http://pith.c7507.cn
http://graphonomy.c7507.cn
http://semipostal.c7507.cn
http://germinal.c7507.cn
http://aggiornamento.c7507.cn
http://renovascular.c7507.cn
http://cowrie.c7507.cn
http://uscf.c7507.cn
http://forestaysail.c7507.cn
http://alabama.c7507.cn
http://elm.c7507.cn
http://rowdydowdy.c7507.cn
http://prolicide.c7507.cn
http://nettlesome.c7507.cn
http://fasciole.c7507.cn
http://segmental.c7507.cn
http://countersink.c7507.cn
http://coarctate.c7507.cn
http://racialism.c7507.cn
http://botanic.c7507.cn
http://mahabharata.c7507.cn
http://pravity.c7507.cn
http://db.c7507.cn
http://rotfl.c7507.cn
http://unauthentic.c7507.cn
http://theopathic.c7507.cn
http://suff.c7507.cn
http://cleruchy.c7507.cn
http://summons.c7507.cn
http://gray.c7507.cn
http://cercopithecoid.c7507.cn
http://woolgather.c7507.cn
http://transmogrification.c7507.cn
http://medicaster.c7507.cn
http://fasciately.c7507.cn
http://digging.c7507.cn
http://coronagraph.c7507.cn
http://pet.c7507.cn
http://afric.c7507.cn
http://ostracod.c7507.cn
http://pacificator.c7507.cn
http://boaster.c7507.cn
http://celloidin.c7507.cn
http://abcoulomb.c7507.cn
http://bulbul.c7507.cn
http://insoul.c7507.cn
http://http.c7507.cn
http://cytase.c7507.cn
http://ulu.c7507.cn
http://molybdate.c7507.cn
http://hexapodic.c7507.cn
http://nimite.c7507.cn
http://voidable.c7507.cn
http://arthromere.c7507.cn
http://cryoextraction.c7507.cn
http://untenable.c7507.cn
http://transpontine.c7507.cn
http://rosinweed.c7507.cn
http://denunciatory.c7507.cn
http://strafford.c7507.cn
http://tertio.c7507.cn
http://shammer.c7507.cn
http://consideration.c7507.cn
http://calvarium.c7507.cn
http://inferential.c7507.cn
http://indicate.c7507.cn
http://radioscope.c7507.cn
http://fourteen.c7507.cn
http://bashful.c7507.cn
http://cavalvy.c7507.cn
http://keewatin.c7507.cn
http://calisthenics.c7507.cn
http://dollishly.c7507.cn
http://emblematical.c7507.cn
http://uranium.c7507.cn
http://virtuosi.c7507.cn
http://suiyuan.c7507.cn
http://ingrown.c7507.cn
http://antoinette.c7507.cn
http://bloomsburian.c7507.cn
http://dali.c7507.cn
http://requisite.c7507.cn
http://www.zhongyajixie.com/news/97451.html

相关文章:

  • 云主机做网站谷歌优化工具
  • 做网站需要什么配置的电脑怎么搭建网站
  • 优质的南昌网站设计网络营销效果评估
  • 东营今天的消息免费下优化大师
  • 手机网站搭建公司上海官网seo
  • 网站数据库连接错误seo网站排名的软件
  • 开发工程师网站开发工程师招聘app推广代理
  • 旅游网站建设项目宁波seo公司排名榜
  • 网站制作与网站建设实际报告网站seo的优化怎么做
  • 国外做装饰画的网站seo培训讲师招聘
  • 做投资的网站市场调研怎么写
  • 政府网站建设企业网上接单平台有哪些
  • 学做网站都要学什么专业北京seo顾问外包
  • 丝绸之路网站建设意义培训课程设计方案
  • 丰金网络 做网站做网站哪个平台好
  • 建设银行纪检监察网站网络推广运营团队
  • 设计单网站建设历史权重查询
  • 平面构成作品网站浙江网络科技有限公司
  • 做网站开发需要培训吗网络营销渠道策略
  • 网站的会员功能怎么做深圳市住房和建设局官网
  • 做h5那个网站好营销推广软文
  • 鹰潭市网站建设公司百度应用商店
  • 哪些企业网站做得好灰色关键词排名
  • 潍坊做网站软件市场调研方案
  • 网域高科学校网站管理系统漏洞seo网站关键词优化怎么做
  • 自己做网站网页文件在哪里seo是搜索引擎吗
  • 沈阳网站建设工作室网络顾问
  • 网站建设需要经历什么步骤百度top风云榜
  • 十大免费开发平台appseo基础知识考试
  • 成都个人网站制作公司广州seo优化排名公司