Example code app.post("/register", (req, res) => { User.findOne({username: req.body.username}, async(err, doc) => { if(err) throw err; if(doc) res.send('User already exist'); if(!doc){ const hashedPassword = await bcrypt.hash(req.body.password, 10); const newUser = new User({ username: req.body.username, password: hashedPassword, }); await newUser.save(); res.send('User Created') } }) }) bcrypt ..
Solution I in Javascript const keyboards = [3, 1]; const drives = [5, 2, 8]; const b = 10; function getMoneySpent(keyboards, drives, b) { let valid = []; keyboards.forEach(k => drives.forEach(d => k + d //1. reduce: arrow function 이용 single value return. //2. max: 조건에 맞게 max value를 리턴. //3. map: 함수이용 each elements 변화시킨다. -> drives와 keyboards each elements 더하기. //4. 합한 값을 budget보다 작거나 같은 값으로 filt..
Solution in Javascript const k = 4; const height = [1, 6, 3, 5, 2]; function hurdleRace(k, height) { const max = Math.max(...height); if ((max - k) The Hurdle Race | HackerRank Determine the maximum value in an array less a value, limit >= 0. www.hackerrank.com
Solution in Javascript const x = 1; const y = 2; const z = 3; function catAndMouse(x, y, z) { const A = Math.abs(z-x); const B = Math.abs(z-y); if (A B){ console.log('Cat B'); }else if (A === B){ console.log('Mouse C'); } } catAndMouse(x, y, z); Reference www.hackerrank.com/challenges/cats-and-a-mouse/problem
Javascript는 type을 쓰지 않으니 원치않는 결과를 가질 때가 있는데 이럴때 아주 간단하게 형변환을 하는 방법이 있다. number + string type "" 은 number to string type conversion string * 1 은 string to number conversion Example code let arr = [1, 2, 3]; console.log(typeof arr); //datatype: object console.log(typeof arr[1]); //datatype: number let changeToString = (arr + "").split(","); //number + "": changed to string console.log(changeToStri..
- Total
- Today
- Yesterday
- 알고리즘
- 프로그래머스 알고리즘
- HackerRank Algorithm
- math.max
- substring()
- spring boot application
- rest parameter
- code refactoring
- algorithm
- 프로그래머스 알고리즘문제
- HashMap
- 프로그래머스
- easy javascript algorithm
- equals()
- easy algorithm
- Collection Framework
- hackerrank solution
- hackerrank javascript solution
- Object type casting
- hackerrank
- repeat()
- ... in Javascript
- string class in java
- compareTo()
- math.abs
- Javascript Algorithm
- java
- C++
- javascript
- hackerrank javascript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |