Fancy DSA Fancy DSA
数据结构
算法
LeetCode
  • 关于
  • 导航 (opens new window)
  • 分类
  • 标签
  • 归档
设计模式 (opens new window)
博客 (opens new window)
GitHub (opens new window)

Jonsam NG

想的更多,也要想的更远
数据结构
算法
LeetCode
  • 关于
  • 导航 (opens new window)
  • 分类
  • 标签
  • 归档
设计模式 (opens new window)
博客 (opens new window)
GitHub (opens new window)
  • 开始上手
  • Plan 计划
  • Roadmap 路线
  • 算法简介
  • Sort 排序

  • Search 搜索

  • Recursive 递归

  • Graph 图

  • Tree 树

  • Math 数学

  • Hash 哈希

  • String 字符串

    • AlphaNumericPalindrome [回文串]
    • AlternativeStringArrange [交替合并字符串]
    • BoyerMoore [博耶-穆尔字符串搜索算法、BM 算法]
    • CheckAnagram [易位构词]
    • NamingConvention [命名规则]
      • 介绍
      • camelCase
      • flatcase
      • kebab-case
      • snake_case
      • PascalCase
      • 参考
    • CheckExceeding [Exceeding words]
    • CheckPangram [全字母句]
    • CheckWordOccurrence [单词计数]
    • CountVowels [元音字母计数]
    • CreatePermutations [全排列]
    • DiceCoefficient [Dice系数]
    • FormatPhoneNumber [格式化电话号码]
    • GenerateGUID [生成GUID、UUID]
    • HammingDistance [汉明距离]
    • KMPPatternSearching [KMP字符串匹配]
  • BitManipulation 位操纵

  • Backtracking 回溯

  • DynamicProgramming 动态规划

  • Cache 缓存

  • Array 数组

  • Ciphers 密码学

  • Conversions 转换

  • ProjectEuler 欧拉计划

  • 其他

  • 算法
  • String 字符串
jonsam
2022-09-26
目录

NamingConvention [命名规则]

# 介绍

程序设计的中命名规则(naming convention)是电脑程序设计的源代码针对标识符的名称字符串进行定义(即 “命名”)而规定的一系列规则。通常是为了提高源代码的易读性、易认性、程序效率以及可维护性。命名规则根据各个程序语言的规格、内存大小等硬件制约、编辑器以及集成开发环境的功能等等会有各种制约。

www

# camelCase

检查是否是驼峰写法。驼峰式大小写(Camel-Case,Camel Case,camel case),计算机程序编写时的一套命名规则(惯例)。当变量名和函数名称是由二个或多个单字连结在一起,而构成的唯一识别字时,利用 “驼峰式大小写” 来表示,可以增加变数和函式的可读性。

检查 camelCase:

// CheckCamelCase method checks the given string is in camelCase or not.

// Problem Source & Explanation: https://en.wikipedia.org/wiki/Camel_case

/**
 * checkCamelCase method returns true if the string in camelCase, else return the false.
 * @param {String} varName the name of the variable to check.
 * @returns `Boolean` return true if the string is in camelCase, else return false.
 */
const checkCamelCase = (varName) => {
  // firstly, check that input is a string or not.
  if (typeof varName !== 'string') {
    throw new TypeError('Argument is not a string.')
  }

  const pat = /^[a-z][A-Za-z]*$/
  return pat.test(varName)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# flatcase

检查 flatcase:

// checkFlatCase method checks if the given string is in flatcase or not. Flatcase is a convention
// where all letters are in lowercase, and there are no spaces between words.
// thisvariable is an example of flatcase. In camelCase it would be thisVariable, snake_case this_variable and so on.

// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)

/**
 * checkFlatCase method returns true if the string in flatcase, else return the false.
 * @param {string} varname the name of the variable to check.
 * @returns {boolean} return true if the string is in flatcase, else return false.
 */
const checkFlatCase = (varname) => {
  // firstly, check that input is a string or not.
  if (typeof varname !== 'string') {
    return new TypeError('Argument is not a string.')
  }

  const pat = /^[a-z]*$/
  return pat.test(varname)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# kebab-case

检查 kebab-case:

// CheckKebabCase method checks the given string is in kebab-case or not.

// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)

/**
 * CheckKebabCase method returns true if the string in kebab-case, else return the false.
 * @param {String} varName the name of the variable to check.
 * @returns `Boolean` return true if the string is in kebab-case, else return false.
 */
const CheckKebabCase = (varName) => {
  // firstly, check that input is a string or not.
  if (typeof varName !== 'string') {
    return new TypeError('Argument is not a string.')
  }

  const pat = /(\w+)-(\w)([\w-]*)/
  return pat.test(varName) && !varName.includes('_')
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# snake_case

检查 snake_case:

// CheckSnakeCase method checks the given string is in snake_case or not.

// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)

/**
 * checkSnakeCase method returns true if the string in snake_case, else return the false.
 * @param {String} varName the name of the variable to check.
 * @returns `Boolean` return true if the string is in snake_case, else return false.
 */
const checkSnakeCase = (varName) => {
  // firstly, check that input is a string or not.
  if (typeof varName !== 'string') {
    throw new TypeError('Argument is not a string.')
  }

  const pat = /(.*?)_([a-zA-Z])*/
  return pat.test(varName)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# PascalCase

检查 PascalCase:

// CheckPascalCase method checks the given string is in PascalCase or not.

// Problem Source & Explanation: https://www.theserverside.com/definition/Pascal-case

/**
 * CheckPascalCase method returns true if the string in PascalCase, else return the false.
 * @param {String} VarName the name of the variable to check.
 * @returns `Boolean` return true if the string is in PascalCase, else return false.
 */
const CheckPascalCase = (VarName) => {
  // firstly, check that input is a string or not.
  if (typeof VarName !== 'string') {
    return new TypeError('Argument is not a string.')
  }

  const pat = /^[A-Z][A-Za-z]*$/
  return pat.test(VarName)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 参考

  • 驼峰式大小写 - Wikiwand (opens new window)
  • Naming convention (programming) - Wikiwand (opens new window)
  • 命名规则 (程序设计) - Wikiwand (opens new window)
编辑 (opens new window)
上次更新: 2022/10/20, 20:03:22
CheckAnagram [易位构词]
CheckExceeding [Exceeding words]

← CheckAnagram [易位构词] CheckExceeding [Exceeding words]→

最近更新
01
0-20题解
10-31
02
本章导读
10-31
03
算法与转换:Part1
10-28
更多文章>
Theme by Vdoing | Copyright © 2022-2022 Fancy DSA | Made by Jonsam by ❤
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式