https://programmers.co.kr/learn/courses/30/lessons/12935
function solution(arr) {
var answer = [];
var lengthOfArr = arr.length;
if(lengthOfArr === 1){
answer = [-1];
}else{
arr.sort((a,b) => b-a);
arr.pop();
answer = arr;
}
return answer;
}
function solution(arr) {
var answer = [];
var lengthOfArr = arr.length;
var min = 0;
var newArr = arr.concat();
newArr.sort((a,b) => b-a);
min = newArr[lengthOfArr-1];
for(var i=0; i<lengthOfArr; i++){
if(arr[i] != min){
answer.push(arr[i]);
}
}
if(answer.length === 0){
answer.push(-1);
}
return answer;
}
function solution(arr) {
var answer = [];
if (arr.length === 1) {
answer = [-1];
} else {
var copiedArr = arr.slice(0);
var sortedArr = copiedArr.sort((a,b) => b-a);
var minElement = sortedArr[sortedArr.length-1];
for ( var i=0; i<arr.length; i++){
// var copiedArr2 = arr.slice(0);
if(arr[i] === minElement){
arr.splice(i,1);
answer = arr;
// for( var index=0; index < arr.length-1; index++){
// if (index < i){
// answer[index] = copiedArr2[index];
// } else {
// answer[index] = copiedArr2[index+1];
// }
// }
}
}
}
return answer;
}
//내림차순 정렬
//제일작은수
JS function - apply (Q. 왜 다른 사람들은 apply를 사용했지?)
array 관련 method - concat(), slice(), push()***, splice()
Math 관련 method - Math.max(). Math.min()
console.log(Math.max(1, 3, 2)); //3
console.log(Math.max(-1, -3, -2)); //-1
const array1 = [1, 3, 2];
console.log(Math.max(...array1)); //3