Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: 修复Eslint校验报错异常,修改部分代码和文档格式 #184

Merged
merged 4 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions code/algorithm/debounce.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* 防抖
* @param func
* @param time
*/
function debounce(func, time) {
let timeout
Expand Down
25 changes: 9 additions & 16 deletions code/algorithm/deepClone.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
/**
* 判断数据类型
*/
function checkType(target) {
// typeof -instanceof -toString.call() -Array.isArray()
return Object.prototype.toString.call(target).slice(8, -1)
}
/**
* 基于Json序列化的深拷贝【不能处理函数】
* @param target
*/
function DeepCloneByJSON(target) {
export function DeepCloneByJSON(target) {
return JSON.parse(JSON.stringify(target))
}

/**
* 基于递归思想的深拷贝
*/
function DeepClone(target) {
export function DeepClone(target) {
let result
const targetType = checkType(target)
if (targetType === 'object') {
Expand All @@ -29,16 +35,3 @@ function DeepClone(target) {
}
return result
}

/**
* 判断数据类型
* @param target
*/
function checkType(target) {
// typeof -instanceof -toString.call() -Array.isArray()
return Object.prototype.toString.call(target).slice(8, -1)
}

// 深拷贝
console.log(DeepCloneByJSON)
console.log(DeepClone)
32 changes: 0 additions & 32 deletions code/algorithm/front-end-ts/add.js

This file was deleted.

3 changes: 2 additions & 1 deletion code/algorithm/front-end-ts/count.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* 计数
* @param str
*/
function count(str: string) {
// 转换为数组后去重
Expand All @@ -22,3 +21,5 @@ function count(str: string) {
}
return result
}

count('12321')
4 changes: 2 additions & 2 deletions code/algorithm/front-end-ts/duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 找出数组 arr 中重复出现过的元素
*/
function duplicates(arr: number[]) {
const sortArr = arr.sort()
const result = []
const sortArr: number[] = arr.sort()
const result: number[] = []
const len = sortArr.length
for (let index = 0; index < len - 1; index++) {
if (sortArr[index] === sortArr[index++]) {
Expand Down
3 changes: 1 addition & 2 deletions code/algorithm/front-end-ts/isUSD.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* 检测是否为USD字符
* @param str
*/
function isUSD(str: string) {
if (!str.startsWith('$')) {
Expand Down Expand Up @@ -33,4 +32,4 @@ function isUSD(str: string) {
return true
}

console.log(isUSD('$20,933,209.93'))
isUSD('$20,933,209.93')
9 changes: 5 additions & 4 deletions code/algorithm/front-end-ts/removeWithoutCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* - 直接在给定的 arr 数组上进行操作,并将结果返回
*/
function removeWithoutCopy(arr: number[], item: number) {
// 第一种方法: filter过滤
// const result= arr.filter(value=>value!==item)
// // 输出
// 输出
// return result;
// 每次都和arr中的首个元素去比较

// 第二种方法:循环遍历,每次都和arr中的首个元素去比较
const len = arr.length
for (let index = 0; index < len; index++) {
if (arr[0] !== item) {
Expand All @@ -19,5 +21,4 @@ function removeWithoutCopy(arr: number[], item: number) {
return arr
}

const test = [1, 2, 2, 3, 4, 2, 2]
console.log(removeWithoutCopy(test, 2))
removeWithoutCopy([1, 2, 2, 3, 4, 2, 2], 2)
7 changes: 3 additions & 4 deletions code/algorithm/front-end/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function add(...inputs) {
return _add
}

const str = add(1, 6)(2)(3)
console.log(str)
console.log(add(1)(2)(3))
console.log(add(1)(2, 3, 4))
add(1, 6)(2)(3)
add(1)(2)(3)
add(1)(2, 3, 4)
4 changes: 1 addition & 3 deletions code/algorithm/front-end/count.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* 计数
* @param str
*/
function count(str) {
// 转换为数组后去重
Expand All @@ -24,5 +23,4 @@ function count(str) {
}

// 调用
const result = count('abTT')
console.log(result)
count('abTT')
2 changes: 1 addition & 1 deletion code/algorithm/front-end/duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ function duplicates(arr) {
return [...new Set(result)]
}

console.log(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]))
duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3])
2 changes: 1 addition & 1 deletion code/algorithm/front-end/isUSD.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ function isUSD(str) {
return true
}

console.log(isUSD('$20,933,209.93'))
isUSD('$20,933,209.93')
3 changes: 1 addition & 2 deletions code/algorithm/front-end/removeWithoutCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ function removeWithoutCopy(arr, item) {
return arr
}

const test = [1, 2, 2, 3, 4, 2, 2]
console.log(removeWithoutCopy(test, 2))
removeWithoutCopy([1, 2, 2, 3, 4, 2, 2], 2)
19 changes: 6 additions & 13 deletions code/algorithm/interview-101/addInList.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
export function ListNode(x) {
this.val = x
this.next = null
}

/**
*
* @param head1 ListNode类
* @param head2 ListNode类
* @return ListNode类
*/
function addInList(head1, head2) {
export function addInList(head1, head2) {
console.log(head1, head2)
}

module.exports = {
addInList,
}
14 changes: 3 additions & 11 deletions code/algorithm/interview-101/binarySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

/**
*
* @param nums
* @param target
*/
const search = function (nums, target) {
// 投机
Expand All @@ -15,8 +13,6 @@ const search = function (nums, target) {

/**
* 二分查找
* @param nums
* @param target
*/
function binarySearch(nums, target) {
let left = 0
Expand All @@ -42,8 +38,6 @@ function binarySearch(nums, target) {

/**
* 左侧部分【第一个相同元素】
* @param nums
* @param target
*/
function leftBound(nums, target) {
let left = 0
Expand Down Expand Up @@ -72,8 +66,6 @@ function leftBound(nums, target) {

/**
* 右侧部分【最后一个相同元素】,[left,right) 情况
* @param nums
* @param target
*/
function rightBound(nums, target) {
let left = 0
Expand Down Expand Up @@ -103,6 +95,6 @@ function rightBound(nums, target) {

const nums = [5, 7, 7, 8, 8, 8, 10]
const target = 8
console.log(search(nums, target))
console.log(leftBound(nums, target))
console.log(rightBound(nums, target))
search(nums, target)
leftBound(nums, target)
rightBound(nums, target)
3 changes: 1 addition & 2 deletions code/algorithm/interview-101/deleteDuplicates-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
/**
*
* @param head ListNode类
* @return ListNode类
*/
function deleteDuplicatesOne(head) {
console.log(head)
}

// 测试用例
console.log(deleteDuplicatesOne(1))
deleteDuplicatesOne(1)
6 changes: 1 addition & 5 deletions code/algorithm/interview-101/entryNodeOfLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
* @param pHead
* @constructor
*/
function entryNodeOfLoop(pHead) {
export function entryNodeOfLoop(pHead) {
console.log(pHead)
}

module.exports = {
entryNodeOfLoop,
}
2 changes: 0 additions & 2 deletions code/algorithm/interview-101/fibonacci.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* 斐波那契数列,递归调用
* 难度:入门
* @param n
* @returns {*}
*/
function fibonacciOne(n) {
return n < 2 ? n : fibonacciOne(n - 1) + fibonacciOne(n - 2)
Expand Down
3 changes: 0 additions & 3 deletions code/algorithm/interview-101/findFirstCommonNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

/**
* 【简单】 两个链表的第一个公共结点
* @param pHead1
* @param pHead2
* @constructor
*/
function findFirstCommonNode(pHead1, pHead2) {
console.log(pHead1, pHead2)
Expand Down
3 changes: 0 additions & 3 deletions code/algorithm/interview-101/findKth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ function quickSort(arr, low, high) {

/**
* 获取节点
* @param arr
* @param low
* @param high
*/
function getPivot(arr, low, high) {
const pivot = arr[low]
Expand Down
1 change: 0 additions & 1 deletion code/algorithm/interview-101/findKthToTail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* 链表结点
*/
// eslint-disable-next-line no-unused-vars,unused-imports/no-unused-vars
function ListNode(x) {
this.val = x
this.next = null
Expand Down
4 changes: 1 addition & 3 deletions code/algorithm/interview-101/findNumbersWithSum.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* 注意array是递增的
* @param array
* @param sum
*/
function FindNumbersWithSum(array, sum) {
let left = 0
Expand Down Expand Up @@ -41,4 +39,4 @@ function FindNumbersWithSum(array, sum) {
return sumResult
}

console.log(FindNumbersWithSum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], 21))
FindNumbersWithSum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], 21)
7 changes: 1 addition & 6 deletions code/algorithm/interview-101/getLeastNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* - 数组元素是4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4。
* - 如果K>数组的长度,那么返回一个空的数组
*/

/**
* 基于冒泡排序
* @param input
* @param k
*/
function GetLeastNumbersSolution(input, k) {
const len = input.length
Expand All @@ -32,8 +31,6 @@ function GetLeastNumbersSolution(input, k) {

/**
* 基于简单选择排序
* @param input
* @param k
*/
function GetLeastNumbersSolution02(input, k) {
const len = input.length
Expand All @@ -58,8 +55,6 @@ function GetLeastNumbersSolution02(input, k) {

/**
* 基于sort函数
* @param input
* @param k
*/
function GetLeastNumbersSolution03(input, k) {
// if (k > input.length) return []
Expand Down
2 changes: 0 additions & 2 deletions code/algorithm/interview-101/getLongestPalindrome.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/**
* 求给定字符的最大回文字符串
* @param str
* @param len
*/
function getLongestPalindrome(str, len) {
let max = 0
Expand Down
6 changes: 1 addition & 5 deletions code/algorithm/interview-101/hasCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* @param head ListNode类
* @return bool布尔型
*/
function hasCycle(head) {
export function hasCycle(head) {
console.log(head)
}

module.exports = {
hasCycle,
}
6 changes: 1 addition & 5 deletions code/algorithm/interview-101/isPail.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
* @param head ListNode类 the head
* @return bool布尔型
*/
function isPail(head) {
export function isPail(head) {
console.log(head)
}

module.exports = {
isPail,
}
Loading
Loading