diff --git "a/src/programmers/javascript/lv1/lv1_\352\260\231\354\235\200\354\210\253\354\236\220\353\212\224\354\213\253\354\226\264.js" "b/src/programmers/javascript/lv1/lv1_\352\260\231\354\235\200\354\210\253\354\236\220\353\212\224\354\213\253\354\226\264.js" new file mode 100644 index 0000000..2a2c819 --- /dev/null +++ "b/src/programmers/javascript/lv1/lv1_\352\260\231\354\235\200\354\210\253\354\236\220\353\212\224\354\213\253\354\226\264.js" @@ -0,0 +1,18 @@ +// function solution(arr) { +// let answer = []; + +// for (const item of arr) { +// if (answer[answer.length - 1] !== item) { +// answer.push(item); +// } +// } + +// return answer; +// } + +function solution(arr) { + return arr.filter((v, i) => v !== arr[i + 1]); +} + +console.log(solution([1, 1, 3, 3, 0, 1, 1])); // [1,3,0,1] +console.log(solution([4, 4, 4, 3, 3])); // [4,3]