Skip to content

Instantly share code, notes, and snippets.

View Thaekeh's full-sized avatar

Thaeke Hekkenberg Thaekeh

View GitHub Profile
@Thaekeh
Thaekeh / basicSlotComponent.vue
Last active May 15, 2021 21:06
Basic Slot Component
<template>
<slot>
Backup text
</slot>
</template>
@Thaekeh
Thaekeh / sortingBoolean.js
Created December 2, 2020 13:23
Sort an array by a Boolean value.
computed: {
sortedRecipes() {
tempArray = tempArray.sort((a, b) => {
if (a.favorite && !b.favorite) {
return -1
} else if (!a.favorite && b.favorite) {
return 1
} else {
return 0
}
@Thaekeh
Thaekeh / completeFilterFunction.js
Created December 2, 2020 12:58
This is the complete sort, filter, and search code.
computed: {
filteredRecipes() {
let tempRecipes = this.recipes
if (this.searchValue != '' && this.searchValue) {
tempRecipes = tempRecipes.filter((item) => {
return item.title
.toUpperCase()
.includes(this.searchValue.toUpperCase())
})
@Thaekeh
Thaekeh / simpleSearch.js
Last active November 4, 2022 23:21
Simple search by using the included() method
computed: {
searchResult() {
let tempRecipes = this.recipes
if (this.searchValue != '' && this.searchValue) {
tempRecipes = tempRecipes.filter((item) => {
return item.title
.toUpperCase()
.includes(this.searchValue.toUpperCase())
})
@Thaekeh
Thaekeh / filterFavorites.js
Created December 2, 2020 11:38
Only return the favorites of an array.
computed: {
filteredRecipes() {
let tempRecipes = this.recipes
tempRecipes = tempRecipes.filter((item) => {
return item.favorite
})
}
}
@Thaekeh
Thaekeh / filteringNumerically.js
Last active December 2, 2020 12:51
With this code you can filter an array based on the cooking time.
computed: {
filteredRecipes() {
let tempRecipes = this.recipes
tempRecipes = tempRecipes.filter((item) => {
return (item.cookingTime <= this.maxCookingTime)
})
return tempRecipes;
}
@Thaekeh
Thaekeh / sortingNumerically.js
Last active January 31, 2023 22:39
Sorting an array numerically
computed: {
sortedArray() {
let sortedRecipes = this.recipes;
if (sortMethod == 'alphabetically' {
sortedRecipes = sortedRecipes.sort((a,b) => {
let fa = a.title.toLowerCase(), fb = b.title.toLowerCase();
if (fa < fb) {
return -1
}
@Thaekeh
Thaekeh / sortingAlphabetically.js
Last active March 15, 2022 15:22
Sort arrays alphabetically
computed: {
sortedArray() {
let sortedRecipes = this.recipes;
sortedRecipes = sortedRecipes.sort((a,b) => {
let fa = a.title.toLowerCase(), fb = b.title.toLowerCase();
if (fa < fb) {
return -1
}
if (fa > fb) {