From cae823bf48e9087fd525fc4d22ab5fb117f41d20 Mon Sep 17 00:00:00 2001 From: koronya Date: Sat, 16 May 2026 05:02:39 +0900 Subject: [PATCH] [JS][7kyu] The dropWhile Function --- .../7kyu/the-drop-while-function/koronya.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 codewars/7kyu/the-drop-while-function/koronya.js diff --git a/codewars/7kyu/the-drop-while-function/koronya.js b/codewars/7kyu/the-drop-while-function/koronya.js new file mode 100644 index 000000000..37375369b --- /dev/null +++ b/codewars/7kyu/the-drop-while-function/koronya.js @@ -0,0 +1,26 @@ +// [JS][7kyu] The dropWhile Function +// the-drop-while-function +// https://www.codewars.com/kata/54f9c37106098647f400080a/train/javascript + +const dropWhile = (array, predicate) => { + let leftSize = 0 + let index = 0 + const arrayLength = array.length + while (index < arrayLength) { + if (predicate(array[index])) { + leftSize += 1 + index += 1 + } else { + break + } + } + + return array.slice(leftSize) +} + +const isEven = (num) => { + return num % 2 === 0 +} +const seq = [2, 4, 6, 8, 1, 2, 5, 4, 3, 2] +dropWhile(seq, isEven) // -> [1,2,5,4,3,2] +dropWhile([72, -45, -5, -41, 86, 75, -83, -45, 48, -91, 81, -5, -61, 97, 78, 18, 83, 0, -1], (num) => num % 2 !== 0)