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
var categories = [ | |
{ | |
id: 0, | |
name: 'Shoes', | |
imageUrl: 'alkfaekfja0-43i' | |
}, | |
{ | |
id: 1, | |
name: 'Clothing', | |
imageUrl: 'someshit' | |
}, | |
{ | |
id: 2, | |
name: 'Facial Care', | |
imageUrl: '' | |
} | |
]; | |
var products = [ | |
{ | |
name: 'Fancy Shoes', | |
categories: [ 0, 1 ] | |
imageUrl: '' | |
}, | |
{ | |
name: 'Some Lipstick', | |
categories: [ 2 ], | |
imageUrl: '' | |
} | |
]; | |
function getCategory ( categoryName ) { | |
for ( var i = 0; i < categories.length; i++ ) { | |
if ( categories[ i ].categoryName === categoryName ) { | |
return categories[ i ]; | |
} | |
} | |
} | |
function getProductsByCategory ( categoryName ) { | |
var category = getCategory( categoryName ); | |
var productsIWant = []; | |
for ( var i = 0; i < products.length; i++ ) { | |
for ( var j = 0; j < products[ i ].categories.length; j++ ) { | |
if ( products[ i ].categories[ j ] === category.id ) { | |
productsIWant.push( products ); | |
} | |
} | |
} | |
return productsIWant; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment