티스토리 뷰

Algorithms

CamelCase

seoca 2021. 2. 12. 14:41

 

WHAT I LEARNED
using regular expression
split() - The separator can also be a regular expression. 정규식을 split()의 separator로 사용가능.

 

let s = "camelCaseHowManyWords"

function CamelCase(str) {
    let re = /[A-Z]/g; //g is global
    //regular expression can separate a string at the instance there is a capitalized letter.
    let wordSplit = str.split(re); 
    let result = wordSplit.length;
    console.log(result); //5
}

CamelCase(s);

 

 

 

 

 

 

Reference

codeburst.io/javascript-algorithm-camelcase-4df119b6216e

'Algorithms' 카테고리의 다른 글

on sale products algorithm  (0) 2021.02.12
How many typos in a string  (0) 2021.02.12
smallest distance  (0) 2021.01.16
Cut the sticks  (0) 2020.12.18
Equalize the Array  (0) 2020.12.11