Created
July 2, 2014 18:22
-
-
Save adaam2/44363f470d638e3dba23 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
</body> | |
</html> |
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 json = [ | |
{ | |
"type": "LOCATION", | |
"name": "St." | |
}, | |
{ | |
"type":"O" | |
}, | |
{ | |
"type": "LOCATION", | |
"name": "Albans" | |
}, | |
{ | |
"type":"O" | |
}, | |
{ | |
"type": "PERSON", | |
"name": "Adam" | |
}, | |
{ | |
"type":"O" | |
}, | |
{ | |
"type": "PERSON", | |
"name": "Bull" | |
}, | |
{ | |
"type":"THING", | |
"name":"Neymar" | |
}, | |
{ | |
"type":"O" | |
}, | |
{ | |
"type":"NOTATHING", | |
"name":"Benzema" | |
} | |
], background = "O"; | |
$(function(){ | |
var prevType = ""; | |
var prevValue = ""; | |
$.each(json,function(i){ | |
var type = json[i].type; | |
if(type != "O") { | |
var name = json[i].name; | |
if(type === prevType) { | |
var combined = prevValue + ' ' + name; | |
console.log(combined); | |
} | |
prevType = type; | |
prevValue = name; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment