Mr.Tree

Results 11 comments of Mr.Tree

```javascript function trim(str, types = ['start', 'end', 'middle']) { types.forEach(type => { switch (type) { case 'start': str = str.replace(/^\s*/, '') break case 'end': str = str.replace(/\s*$/, '') break case...

```javascript function padArray(arr, i, min, max) { const length = arr.length if (arr[length - 1]) return arr const random = Math.min(Math.ceil(Math.random() * max + min), max - 1) if (!arr.includes(random))...

# [css] 第1天 圣杯布局和双飞翼布局的理解和区别,并用代码实现 > 两者解决类似的问题。主要解决左右定宽,中间自适应的三栏布局。并且中间栏优先渲染。 ## 圣杯布局 >三栏利用 `float` 和 负`margin` 并列 >利用父容器设置 `padding` 给两边侧栏腾空间 ```html bilibili ``` ```css * { padding: 0; margin: 0; } .wrapper1 { padding:...

```javascript const flatArray = array => array.reduce( (pre, item) => Array.isArray(item) ? [...pre, ...flatArray(item)] : [...pre, item], [] ) const uniqueArray = (array, fn = (a, b) => a ===...

```javascript const swap = (arr, index1, index2) => { ;[arr[index1], arr[index2]] = [arr[index2], arr[index1]] } export default function shuffle(arr = []) { if (!Array.isArray(arr)) return let index = arr.length -...

```javascript const isType = type => target => Object.prototype.toString.call(target) === `[object ${type}]` const isArray = isType('Array') const isObject = isType('Object') function extend(target, source, deep) { for (const key in source)...

```javascript function deleteSpecifiedLastCharacter(str, char) { if (!char || typeof str !== 'string' || typeof char !== 'string') return str return str.replace(new RegExp(`${char}(?=([^${char}]*)$)`), '') } ```

```javascript const countString = (str, chars) => ( (arr = str.match(new RegExp(chars, 'g'))), arr && chars ? arr.length : 0 ) ```

```javascript const underlineToBigHump = str => typeof str === 'string' ? str .split('_') .map(item => item.toLocaleLowerCase()) .reduce( (pre, item) => item ? `${pre}${item[0].toLocaleUpperCase()}${item.slice(1)}` : pre, '' ) : str ```

```javascript const parsingURLSearch = url => { const searchs = url.match(/[^?&=]*=[^?&=]*/g) return ( searchs && searchs.reduce( (pre, s) => ({ ...pre, [s.split('=')[0]]: s.split('=')[1] }), {} ) ) } ```