Study Notes

Study Notes

  • Source
  • WebDesign
  • Javascript

›Basic Algorithm Script

Basic Javascript

  • Basic JavaScript Overview

ES6

  • ES6 Overview

Regular expression

  • Regular Expression Overview
  • Lookahead
  • Capture Group

Debugging

  • Debugging Overview

Object Oriented Programming

  • Object Oriented Programming Overview
  • Mixin
  • Closure
  • IIFE

Functional Programming

  • Functional Programming

Basic Algorithm Script

  • Reverse a String
  • Factorialize a Number
  • Find the Longest Word in a String
  • Return Largest Numbers In Arrays
  • Repeat a String
  • Truncate a String
  • Finders Keepers
  • Boo Who
  • Title Case a Sentence
  • Slice and Splice
  • Falsy Bouncer
  • javascript-algorithms-anddata-structures/basic-algorithm-scripting/where-do-i-belong
  • Mutations
  • Chunky Monkey

Intermediate Algorithm Script

  • Sum All Numbers in a Range
  • Diff Two Arrays
  • Seek and Destroy
  • Wherefor Art Thou
  • Spinal Tap Case
  • Search and Replace
  • DNA Pairing
  • Missing letters
  • Sorted Union
  • Convert HTML Entities
  • Sum All Odd Fibonacci Numbers
  • Smallest Common Multiple
  • Drop it
  • Steamroller
  • Binary Agents
  • Everything Be True
  • Arguments Optional
  • Make a Person
  • Map the Debris

Reverse a String

这个知识点的思路并不难,主要步骤:

  • 将字符串转换为数组
  • 用 reverse() 处理数组
  • 将数组转换成字符串

有问题的地方在于 freeCodeCamp 给出的提示是利用 split() 去分离字符串中的每个字符。这个其实处理有缺陷,更好的处理方式可以参考 stack overflow 中给出的处理方法。

究竟为啥用 split() 去处理不妥,链接中有解释。

这个 stack overflow 的答案给出的是利用 ES2015 的新特性去处理,主要有三种方式:

  • 利用扩展运算符
  • 利用 Array.from() 处理
  • 利用 RegExp 中的 u flag
← Functional ProgrammingFactorialize a Number →
Copyright © 2019 罗惠东