Last active
October 21, 2022 00:37
-
-
Save adeleke5140/0825c87d9c361d396d39568b093d43b9 to your computer and use it in GitHub Desktop.
Javascript filter method using the closure feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [1, 2, 3, 4, 5, 6, 7]; | |
function inBetween(a,b){ | |
return function(num){ | |
return (num >=a && num <= b) | |
} | |
} | |
function inArray(arr){ | |
return function(x){ | |
return arr.includes(x) | |
} | |
} | |
const newArr = arr.filter(inBetween(3,6)) | |
const matchArr = arr.filter(inArray([1,2,10])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment