일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 언젠간가겠지
- 퍼블리싱
- chart.js
- 2020
- 리엑트할수있는퍼블리셔라규
- 포트폴리오
- new set()
- classList add
- windowwidth
- react-router
- classList
- 내배위의고양이
- 클래스 토글
- 방심은금물
- classList toggle
- 를
- classList remove
- chart responsive
- react-router-dom
- 접근성
- 안짤렸다
- 간식금지다!
- ROUTER 버전6
- 커스텀훅
- className
- set()
- 냥빨이다가온다
- react
- 배열중복제거
- 대표님물리기없기
Archives
- Today
- Total
틈
[2021-08-05] 배열에서 성격이 다른 하나 골라내기 본문
Question :
배열에서 하나의 짝수나, 하나의 홀수를 걸러내자.
Answer :
function findOutlier(integers){
var d = integers.map(a=> a % 2 === 0 ? 1 : 0).reduce((a,b) => a + b);
return d <= 1
? integers.reduce((a,b)=> parseInt(b) % 2 === 0 ? b : a)
: integers.reduce((a,b)=> parseInt(b) % 2 === 1 || parseInt(b) % 2 === -1 ? b : a);
}
anotherAnswer :
function findOutlier(int){
var even = int.filter(a=>a%2==0);
var odd = int.filter(a=>a%2!==0);
return even.length==1? even[0] : odd[0];
}
'code > Daily Side Project' 카테고리의 다른 글
[2021-08-08] 2개 객체 비교하기 (0) | 2021.08.08 |
---|---|
[2021-08-05] 숫자탑 마지막 줄 구하기 (0) | 2021.08.05 |
[2021-08-05] 객체로 전화번호 만들기 (0) | 2021.08.05 |
[2021-08-05] 특정 단어에서 특정 문자 골라내기 (0) | 2021.08.05 |
[2021-06-02] 그래프 (0) | 2021.06.02 |
Comments