티스토리 뷰
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
'Algorithms' 카테고리의 다른 글
Cats and a Mouse (0) | 2020.09.17 |
---|---|
Find Digits (0) | 2020.09.13 |
Birthday Chocolate (0) | 2020.09.11 |
Divisible Sum Pairs (0) | 2020.09.05 |
Breaking the Records (0) | 2020.09.04 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- spring boot application
- javascript
- HashMap
- Object type casting
- Collection Framework
- string class in java
- 프로그래머스 알고리즘문제
- easy algorithm
- hackerrank solution
- algorithm
- 알고리즘
- equals()
- rest parameter
- hackerrank javascript solution
- 프로그래머스
- 프로그래머스 알고리즘
- java
- Javascript Algorithm
- compareTo()
- substring()
- hackerrank javascript
- HackerRank Algorithm
- math.abs
- ... in Javascript
- C++
- repeat()
- math.max
- hackerrank
- easy javascript algorithm
- code refactoring
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함