1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-04-14 18:30:30 +08:00

[4.25 更新前端部分算法]

This commit is contained in:
mmdapl
2021-04-25 07:37:39 +08:00
parent 2e80e78aff
commit 28d2ddfdc0
7 changed files with 200 additions and 3 deletions

View File

@@ -265,7 +265,7 @@
<div align="left">
<img src="https://s3.ax1x.com/2021/03/13/6wdNy4.jpg" width="300" height="300" style="border-radius:5px;" />
<img src="https://cdn.jsdelivr.net/gh/lir0115/images@main/qr_code/wechat_donate.png" width="300" height="300" style="border-radius:5px;" />
</div>
@@ -277,7 +277,7 @@
有任何问题或建议,欢迎微信`骚扰`,商务合作请备注!
<div align="left">
<img src="https://s3.ax1x.com/2021/03/13/6wdDFx.jpg" width="300" height="300" style="border-radius:5px;"/>
<img src="https://cdn.jsdelivr.net/gh/lir0115/images@main/qr_code/wechat_code.jpg" width="300" height="300" style="border-radius:5px;"/>
</div>
@@ -315,7 +315,7 @@
<p>
<img src="https://cdn.jsdelivr.net/gh/lir0115/images@main/gongzhonghao.jpg" style="border-radius:10px;">
<img src="https://cdn.jsdelivr.net/gh/lir0115/images@main/qr_code/gongzhonghao.jpg" style="border-radius:10px;">
</p>

BIN
算法/.DS_Store vendored

Binary file not shown.

46
算法/前端/add.js Normal file
View File

@@ -0,0 +1,46 @@
/*
* @Description:
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2021-04-23 07:50:21
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-04-23 22:05:34
*/
function add(){
console.log(arguments);
var args=Array.prototype.slice.call(arguments)
console.log(args)
var _add=function(){
console.log('add',arguments)
args.push(...arguments);
// 返回函数
return _add;
}
console.log(args)
// 对参数数组做求和处理
_add.toString=function(){
// 设置sum的起始值为0
return args.reduce((sum,item)=>{
console.log(sum,item)
return sum+item;
})
}
// 返回函数
return _add
}
let str=add(1,6)(2)(3)
console.log(str)
// console.log(String(add(1,6)(2)(3)) )
// console.log(add(1)(2)(3))
// console.log(add(1)(2,3,4))

31
算法/前端/count.js Normal file
View File

@@ -0,0 +1,31 @@
/*
* @Description: 字符串中字符出现频率计数
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2021-04-14 10:21:39
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-04-14 10:22:19
*/
function count(str) {
// 转换为数组后去重
const originArr=str.split('')
const arr=[...new Set(originArr)];
let result={};
for(let index=0;index<arr.length;index++){
const value=arr[index];
let count=0;
if(value!==' '){
originArr.map(item=>{
if(item===value){
count++
}
})
// 对象计数
result[value]=count
}
}
return result;
}

View File

@@ -0,0 +1,30 @@
/*
* @Description: 找出数组 arr 中重复出现过的元素
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2021-04-14 10:22:51
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-04-14 10:22:51
*/
// 找出数组 arr 中重复出现过的元素
function duplicates(arr) {
const sortArr=arr.sort();
let result=new Array()
const len=sortArr.length;
for(let index=0;index<len-1;index++){
if(sortArr[index]===sortArr[index++]){
result.push(sortArr[index])
}
}
// 去重
return [...new Set(result)];
}
console.log(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]))

46
算法/前端/isUSD.js Normal file
View File

@@ -0,0 +1,46 @@
/*
* @Description:
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2021-04-21 07:15:31
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-04-21 12:01:57
*/
function isUSD (str) {
if (!str.startsWith('$')) {
return false;
}
if (str.indexOf('.')) {
// 小数
let arr = str.split('.');
if (arr[1].length !== 2) {
return false;
};
let strArr = arr[0].split(',');
for (let index = 0; index < strArr.length; index++) {
if (strArr[index].length !== 3) {
return false;
}
}
return true;
}
let strArr = str.split(',');
for (let index = 0; index < strArr.length; index++) {
if (strArr[index].length !== 3) {
return false;
}
}
return true;
}
console.log(isUSD('$20,933,209.93'))

View File

@@ -0,0 +1,44 @@
/*
* @Description: 【FED19】 移除数组中的元素
* @Version: Beta1.0
* @Author: 【B站&公众号】Rong姐姐好可爱
* @Date: 2021-04-13 22:47:38
* @LastEditors: 【B站&公众号】Rong姐姐好可爱
* @LastEditTime: 2021-04-14 10:23:19
*/
/**
* 移除数组 arr 中的所有值与 item 相等的元素,直接在给定的 arr 数组上进行操作,并将结果返回
* @param {*} arr
* @param {*} item
* @returns
*/
function removeWithoutCopy(arr, item) {
// const result= arr.filter(value=>value!==item)
// // 输出
// return result;
// 每次都和arr中的首个元素去比较
const len=arr.length;
for(let index=0;index<len;index++){
if(arr[0]!==item){
arr.push(arr[0])
}
// 删除第一个
arr.shift()
}
return arr;
}
const test = [1, 2, 2, 3, 4, 2, 2]
console.log(removeWithoutCopy(test,2))