Spinal Tap case-freecodecamp Algorithm Topic

Source: Internet
Author: User
Spinal Tap case

1. Requirements

  • Converts a string to a spinal case.
  • Spinal case is all-lowercase-words-joined-by-dashes in this form, that is, connecting all lowercase words with hyphens.

2. Ideas

  • Use. Replace () and regular expressions to separate lowercase letters and capitals with a space
  • Again

3. Replace the space with a '-' and finally lowercase.

function spinalCase(str) {  var regex = /\s+|_+/g;  str = str.replace(/([a-z])([A-Z])/g, ‘$1 $2‘);  return str.replace(regex, ‘-‘).toLowerCase();}spinalCase(‘This Is Spinal Tap‘);

4. RELATED LINKS

  • Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp
  • Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/replace

Spinal Tap case-freecodecamp Algorithm Topic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.