Skip to content

Instantly share code, notes, and snippets.

@adeleke5140
Last active October 21, 2022 00:37
Show Gist options
  • Save adeleke5140/0825c87d9c361d396d39568b093d43b9 to your computer and use it in GitHub Desktop.
Save adeleke5140/0825c87d9c361d396d39568b093d43b9 to your computer and use it in GitHub Desktop.
Javascript filter method using the closure feature
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