Skip to content

Instantly share code, notes, and snippets.

@ayxos
Last active August 29, 2015 13:56
Show Gist options
  • Save ayxos/9227515 to your computer and use it in GitHub Desktop.
Save ayxos/9227515 to your computer and use it in GitHub Desktop.
function contains(arr, element) {
var i = arr.length;
var elementToInt = parseInt(element, 10);
while (i--) {
if ( arr[i] === elementToInt) {
return true;
}
}
return false;
}
function showAll(a){
for (var i = a.length - 1; i >= 0; i--) {
// display all elements
document.getElementById(a[i].id).style.display = 'inline-block';
}
}
function getMatch(obj, cat, country){
var match = [];
if ( (cat !== '0') && (country !== '0') ){
for( var i=0; i<obj.length;i++){
document.getElementById(obj[i].id).style.display = 'none';
if ( (contains( obj[i].categories, cat) === true) && (obj[i].owner.nationality === country) ){
document.getElementById(obj[i].id).style.display = 'inline-block';
}
}
}
else{
if(cat === '0'){
for( var j=0; j<obj.length;j++){
document.getElementById(obj[j].id).style.display = 'none';
if (obj[j].owner.nationality === country) {
document.getElementById(obj[j].id).style.display = 'inline-block';
}
}
}
else{
for( var k=0; k<obj.length;k++){
document.getElementById(obj[k].id).style.display = 'none';
if (contains( obj[k].categories, cat) === true) {
document.getElementById(obj[k].id).style.display = 'inline-block';
}
}
}
}
}
describe("searchResult", function() {
var entry = [{'id': 170, "owner": {"nationality": 2},'categories': [2, 3, 1]}, {'id': 168, "owner": {"nationality": 5}, 'categories': []}, {'id': 153, "owner": {"nationality": 1}, 'categories': [1, 5]} ];
var fixture = '<div style="display: inline-block;" id="170"></div><div style="display: inline-block;" id="168"></div><div style="display: inline-block;" id="153"></div>';
document.write(fixture);
it("Giving an HTML with 'display: inline-block', due to mismatch, method turns into 'display:none'", function() {
getMatch(entry, 1, 1);
expect(document.getElementById('170').style.display).toEqual('none');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment