diff --git a/README.md b/README.md index da2f853..3609e17 100644 --- a/README.md +++ b/README.md @@ -1051,21 +1051,33 @@ Removes all provided values from the given array using strict equality for compa ```js // Lodash - var array = [1, 2, 3, 1, 2, 3]; + const array = [1, 2, 3, 1, 2, 3]; _.pull(array, 2, 3); - console.log(array) - // output: [1, 1] + console.log(array); // output: [1, 1] + ``` - // Native - var array = [1, 2, 3, 1, 2, 3]; + ```js + // Native JS + const array = [1, 2, 3, 1, 2, 3]; function pull(arr, ...removeList){ var removeSet = new Set(removeList) return arr.filter(function(el){ return !removeSet.has(el) }) } - console.log(pull(array, 2, 3)) - // output: [1, 1] + console.log(pull(array, 2, 3)); // output: [1, 1] + console.log(array); // still [1, 2, 3, 1, 2, 3]. This is not in place, unlike lodash! + ``` + + ```ts + // TypeScript + const array = [1, 2, 3, 1, 2, 3]; + const pull = (sourceArray: T[], ...removeList: T[]): T[] => { + const removeSet = new Set(removeList); + return sourceArray.filter(el => !removeSet.has(el)); + }; + console.log(pull(array, 2, 3)); // output: [1, 1] + console.log(array); // still [1, 2, 3, 1, 2, 3]. This is not in place, unlike lodash! ``` #### Browser Support for `Array.prototype.filter()`