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]; //두개 이상의 ..
Solution in JavaScript I const s = 7; const t = 10; const a = 4; const b = 12; const apples = [2, 3, -4]; const oranges = [3, -2, -4]; function countApplesAndOranges(s, t, a, b, apples, oranges) { let k = 0; let j = 0; let i; for (i = 0; i = s && a + apples[i] = s && b + oranges[i] value + a >= s && value + a value + b >= s && value + b
- Total
- Today
- Yesterday
- HashMap
- Collection Framework
- C++
- algorithm
- spring boot application
- hackerrank javascript solution
- substring()
- Object type casting
- java
- math.abs
- hackerrank
- javascript
- 프로그래머스 알고리즘문제
- compareTo()
- 알고리즘
- math.max
- hackerrank javascript
- string class in java
- rest parameter
- 프로그래머스 알고리즘
- code refactoring
- hackerrank solution
- repeat()
- easy algorithm
- equals()
- Javascript Algorithm
- easy javascript algorithm
- 프로그래머스
- ... in Javascript
- HackerRank Algorithm
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |