Created
December 2, 2020 12:58
-
-
Save Thaekeh/11e3d60d1dd1a0074ba24de4a1aef0ed to your computer and use it in GitHub Desktop.
This is the complete sort, filter, and search code.
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
computed: { | |
filteredRecipes() { | |
let tempRecipes = this.recipes | |
if (this.searchValue != '' && this.searchValue) { | |
tempRecipes = tempRecipes.filter((item) => { | |
return item.title | |
.toUpperCase() | |
.includes(this.searchValue.toUpperCase()) | |
}) | |
} | |
if (this.maxCookingTime) | |
tempRecipes = tempRecipes.filter((item) => { | |
return (item.cookingTime <= this.maxCookingTime) | |
}) | |
tempRecipes = tempRecipes.sort((a, b) => { | |
if (this.sortBy == 'alphabetically') { | |
let fa = a.title.toLowerCase(), fb = b.title.toLowerCase() | |
if (fa < fb) { | |
return -1 | |
} | |
if (fa > fb) { | |
return 1 | |
} | |
return 0 | |
} else if (this.sortBy == 'cookingTime') { | |
return a.cookingTime - b.cookingTime | |
} | |
}) | |
if (!this.ascending) { | |
tempRecipes.reverse() | |
} | |
return tempRecipes | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment