From 6b579acf357baf3e66a9423c3f30c1bfe77946fa Mon Sep 17 00:00:00 2001 From: Taegwan Youn Date: Sun, 20 Aug 2023 22:49:23 +0900 Subject: [PATCH] Feat: add last --- difference.js | 4 ++++ last.js | 11 +++++++++++ tempCodeRunnerFile.js | 1 + 3 files changed, 16 insertions(+) create mode 100644 last.js create mode 100644 tempCodeRunnerFile.js diff --git a/difference.js b/difference.js index ba76f72..e9254cf 100644 --- a/difference.js +++ b/difference.js @@ -1,4 +1,8 @@ function difference(array, values) { + if (!Array.isArray(array) || !Array.isArray(values)) { + throw new Error('배열 정보를 입력하세요!'); + } + const newArray = array.filter((item) => !values.includes(item)); return newArray; } diff --git a/last.js b/last.js new file mode 100644 index 0000000..c1fca1a --- /dev/null +++ b/last.js @@ -0,0 +1,11 @@ +function last(array) { + if (!Array.isArray(array)) { + throw new Error('배열 정보를 입력하세요!'); + } + + if (array.length === 0) { + return undefined; + } else { + return array[array.length - 1]; + } +} diff --git a/tempCodeRunnerFile.js b/tempCodeRunnerFile.js new file mode 100644 index 0000000..8bd9e94 --- /dev/null +++ b/tempCodeRunnerFile.js @@ -0,0 +1 @@ +return undefined; \ No newline at end of file