Solution I in Javascript function solve(n) { //toString: number to string // 1012 //split: split("")는 string split into an array of substrings //하나하니의 element로 나누기 위해서 기준을 빈칸이없는 ''로 잡는다 // [1,0,1,2] //filter: 전체 element중 조건을 통과한 element로 new array 만든다 return n.toString().split('').filter(i => n % i === 0).length } console.log(solve(1012)); //3 Solution II in Javascript function solve(n) { let st..
Solution in JavaScript const arr = [3, 10, 2, 9]; const k = 1; const b = 12; function solve(bill, k, b) { bill[k] = 0; // 해당 index를 제외하고 시작. let sum = bill.reduce((x,y) => x + y); // reduce로 전부 sum let each = sum / 2; if(each === b){ console.log('Bon Appetit'); } else { console.log(b - each); } } solve(arr, k, b); //loop해서 k의 index를 제외하는 것 -> 해당 index에 0을 넣기.(이 생각을 내가 왜 못했을까!) Reference www.hack..
Solution in JavaScript const arr = [1, 2, 1, 3, 2]; const d = 3; const m = 2; function birthday(s, d, m) { let result = 0; for (let i = 0; i x + y) === d) { result++; } } //return result; console.log(result); } birthday(arr, d, m); //1. 길이만큼 loop을 돌려야하나? -> 2번 //..
Solution in JavaScript const arr = [1, 3, 2, 6, 1, 2]; const k = 3; const n = arr.length; function Divisible_Sum_Pairs(n, k, ar) { let num = 0; for(let i = 0; i < n; i++) { //condition 'i < j' 는 i보다 j가 index number로서 우선할 수 없다는 의미지 값이 커야한다는 의미가 아님. //문제 제대로 읽기! for(let j = (i + 1); j < n; j++){ if((ar[i] + ar[j]) % k === 0){ // 계산순서위한 () 잊지말것. ++num; } } } console.log(num); } Divisible_Sum_Pairs(..
Solution in JavaScript const scores = [10, 5, 20, 20, 4, 5, 2, 25, 1]; function breakingRecords(scores) { let [max, min] = [scores[0], scores[0]]; //중복배열로 선언 let [maxCount, minCount] = [0, 0]; for (let i = 1; i max) { //array로 넣어야지... max = scores[i]; maxCount++ } if (scores[i] < min) { min = scores[i]; minCount++ } } return [maxCount, minCount]; //두개 이상의 ..
- Total
- Today
- Yesterday
- 알고리즘
- C++
- equals()
- hackerrank javascript
- ... in Javascript
- hackerrank javascript solution
- math.abs
- hackerrank solution
- compareTo()
- code refactoring
- algorithm
- Collection Framework
- java
- easy javascript algorithm
- spring boot application
- Javascript Algorithm
- easy algorithm
- HashMap
- repeat()
- Object type casting
- hackerrank
- string class in java
- substring()
- math.max
- javascript
- HackerRank Algorithm
- 프로그래머스
- 프로그래머스 알고리즘문제
- 프로그래머스 알고리즘
- rest parameter
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |