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..
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]; //두개 이상의 ..
Problem You are in charge of the cake for your niece's birthday and have decided the cake will have one candle for each year of her total age. When she blows out the candles, she’ll only be able to blow out the tallest ones. Your task is to find out how many candles she can successfully blow out. For example, if your niece is turning 4years old, and the cake will have 4candles of height 4,4,1,3 ..
- Total
- Today
- Yesterday
- repeat()
- java
- C++
- Object type casting
- 프로그래머스 알고리즘
- code refactoring
- easy algorithm
- compareTo()
- hackerrank javascript
- javascript
- hackerrank solution
- Collection Framework
- Javascript Algorithm
- substring()
- HashMap
- 프로그래머스
- equals()
- string class in java
- easy javascript algorithm
- hackerrank
- HackerRank Algorithm
- spring boot application
- 프로그래머스 알고리즘문제
- math.max
- ... in Javascript
- math.abs
- algorithm
- rest parameter
- hackerrank javascript solution
- 알고리즘
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |