연속된 SOS String에 몇개의 typo가 있는지 알아내는 문제 let s = "SOFSOSSISSOW"; function checkTypo(s) { let sosCount = s.length/3; //몇개의 덩어리인지 check. let sosStr = "SOS".repeat(sosCount); //그 덩어리만 제대로된 SOSSOSSOS print let err = 0; //string 도 for loop. for(let i = 0; i < s.length; i++){ if(s[i] !== sosStr[i]){ err++; } } console.log(err); } checkTypo(s); //3
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 }..
find the smallest distance in a given array. const arr = [1, 4, 2, 2, 1, 5]; function smallestDistance(arr) { const distanceArray = []; for (let i = 0; i < arr.length; i++) { if (arr.lastIndexOf(arr[i]) !== arr.indexOf(arr[i])) { let distance = arr.lastIndexOf(arr[i]) - arr.indexOf(arr[i]) //get the distance distanceArray.push(distance); //push to new array } } distanceArray.sort() //sort consol..
1. This single line of short circuit evaluation is let value = options && options.value || ''; equal to this code let value; if(options){ value = options.value; } else value = ''; 2. stick > min && target.push(stick - min); if(stick > min){ target.push(stick - min); }
Spread Operator in Javascript 1. In ES6, By using the spread operator, you can simply populate an array to another array. '=' only allows you to copy the reference not the value of the array. '=' 는 단지 주소값을 전달할 뿐 진짜 값을 전달하지 못하기때문에 spread operator를 사용해서 array를 복사할 수 있다. function threeDots(arr) { let sticks = [...arr]; } 2. Math.min() and Math.max() expect a list of arguments not an array. If you w..
- Total
- Today
- Yesterday
- 프로그래머스
- compareTo()
- javascript
- 프로그래머스 알고리즘문제
- equals()
- hackerrank javascript solution
- algorithm
- Object type casting
- 프로그래머스 알고리즘
- math.max
- math.abs
- HackerRank Algorithm
- easy javascript algorithm
- ... in Javascript
- HashMap
- code refactoring
- hackerrank
- C++
- string class in java
- easy algorithm
- Javascript Algorithm
- java
- hackerrank solution
- rest parameter
- 알고리즘
- Collection Framework
- hackerrank javascript
- spring boot application
- substring()
- repeat()
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |