function removeExtremes(arr) {
//['where', 'is', 'the', 'longest', 'word']
let shortest = { leng : 20, idx : undefined }
let longest = { leng : 0, idx : undefined }
arr.map((el, idx) => {
if(el.length <= shortest.leng){
shortest.leng = el.length;
shortest.idx = idx;
} else if(el.length >= longest.leng){
longest.leng = el.length;
longest.idx = idx;
}
})
let result = [];
//가장 짧은것과 긴것을 0으로 대체(idx가 바뀌는 것 방지)
arr.splice(shortest.idx, 1, 0);
arr.splice(longest.idx, 1, 0);
//0 없애기
return arr.filter(el => el !== 0);
}
function findBugInApples(arr) {
let result = [];
for(let i = 0; i < arr.length; i++) {
arr[i].map((el, idx) => {
if(el === 'B') {
result.push(i);
result.push(idx);
}
})
}
return result;
}
function readVertically(arr) {
let result = '';
let max = 0;
arr.forEach(el => {
if(el.length > max) max = el.length;
})
for(let i = 0; i < max; i++){
for(let j = 0; j < arr.length; j++){
if(arr[j][i] !== undefined) result += arr[j][i];
}
}
return result;
}
이상하게 이 문제가 안풀려서 검색의 힘을 좀 받았다.
나중에 다시한번 풀어봐야지 될 것 같음...!!!
function superIncreasing(arr) {
let before = arr[0]
for(let i = 1; i < arr.length; i++){
if(before < arr[i]){
before = before + arr[i];
} else {
return false;
}
}
return true;
}