zoukankan      html  css  js  c++  java
  • 前端面试题:驼峰体与匈牙利语法的相互转换

     1 /* 
     2             驼峰体转匈牙利
     3         */
     4         function TfToXyl(params) {
     5             if (typeof params === 'string') {
     6                 let reg = /^[A-Z]+$/
     7                 let strArr = params.split('')
     8                 let result;
     9                 for (let i = 0; i < strArr.length; i++) {
    10                     if (reg.test(strArr[i]) === true) {
    11                         strArr[i] = `_${strArr[i].toLowerCase()}`
    12                     }
    13                 }
    14                 result = strArr.join('').slice(1)
    15                 return result
    16             } else {
    17                 throw new Error(`${params} is not a string`)
    18             }
    19         }
    /* 
               匈牙利转驼峰体
            */
            function xylToTf(params) {
                if (typeof params === 'string') {
                    let result = [];
                    params.split('_').forEach(e => {
                        e = `${e.charAt(0).toUpperCase()}${e.slice(1)}`
                        result.push(e)
                    })
                    result = result.join('')
                    return result
                } else {
                    throw new Error(`${params} is not a string`)
                }
            }
  • 相关阅读:
    fastjson-alibaba
    ubuntu 入门
    资料文档
    asp.net mvc View视图相关
    视频
    js第三方
    工具类网址
    [转]初学者的编程自学指南
    seajs的使用--主要了解模块化
    其它
  • 原文地址:https://www.cnblogs.com/blucesun/p/13183027.html
Copyright © 2011-2022 走看看