Skip to content

Instantly share code, notes, and snippets.

@Qasem-h
Last active September 24, 2019 13:00
Show Gist options
  • Save Qasem-h/af8210c1f059173961d887f11e5cfc57 to your computer and use it in GitHub Desktop.
Save Qasem-h/af8210c1f059173961d887f11e5cfc57 to your computer and use it in GitHub Desktop.
let data = {
results: [
{
type: "MA",
CN: "3",
DO: "1",
FF: "",
FI: "83025411",
I2: "1,6",
IB: "0",
ID: "10124",
IM: "1",
IR: "",
IT: "82783522C1-10124_1_1",
MM: "",
NA: "Match Goals",
OR: "4",
OT: "0",
SU: "0",
TO: "1~GD",
UC: ""
},
{
type: "CO",
CN: "1",
ID: "2",
IT: "82783522C1-10124-2_1_1",
NA: "Count : 0",
OR: "0",
PY: "eh",
SY: "9"
},
{
type: "PA",
FI: "83025411",
HA: "",
HD: "",
ID: "0",
IT: "P83025411C1-50218_1_1",
NA: "0.5",
OD: "",
OR: "0",
SU: "1"
},
{
type: "PA",
FI: "83025411",
HA: "",
HD: "",
ID: "0",
IT: "P83025411C1-10124_1_1",
NA: "1.5",
OD: "",
OR: "1",
SU: "1"
},
{
type: "PA",
FI: "83025411",
HA: "",
HD: "",
ID: "0",
IT: "P83025411C1-50211_1_1",
NA: "2.5",
OD: "",
OR: "2",
SU: "1"
},
{
type: "PA",
FI: "83025411",
HA: "",
HD: "",
ID: "0",
IT: "P83025411C1-50212_1_1",
NA: "3.5",
OD: "",
OR: "3",
SU: "1"
},
{
type: "PA",
FI: "83025411",
HA: "",
HD: "",
ID: "0",
IT: "P83025411C1-50213_1_1",
NA: "4.5",
OD: "",
OR: "4",
SU: "1"
},
{
type: "CO",
CN: "1",
ID: "1",
IT: "82783522C1-10124-1_1_1",
NA: "Over",
OR: "1",
SY: "10"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "0.5",
HD: " 0.5",
ID: "303475121",
IT: "P83025411-303475121C1-_1_1",
NA: "Over ",
OD: "1/8",
OR: "0",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "1.5",
HD: " 1.5",
ID: "303474958",
IT: "P83025411-303474958C1-_1_1",
NA: "Over ",
OD: "4/7",
OR: "1",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "2.5",
HD: " 2.5",
ID: "303475108",
IT: "P83025411-303475108C1-_1_1",
NA: "Over ",
OD: "7/4",
OR: "2",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "3.5",
HD: " 3.5",
ID: "303475111",
IT: "P83025411-303475111C1-_1_1",
NA: "Over ",
OD: "5/1",
OR: "3",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "4.5",
HD: " 4.5",
ID: "303475113",
IT: "P83025411-303475113C1-_1_1",
NA: "Over ",
OD: "12/1",
OR: "4",
SU: "0"
},
{
type: "CO",
CN: "1",
ID: "3",
IT: "82783522C1-10124-3_1_1",
NA: "Under",
OR: "2",
SY: "10"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "0.5",
HD: " 0.5",
ID: "303475122",
IT: "P83025411-303475122C1-_1_1",
NA: "Under ",
OD: "5/1",
OR: "0",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "1.5",
HD: " 1.5",
ID: "303474959",
IT: "P83025411-303474959C1-_1_1",
NA: "Under ",
OD: "5/4",
OR: "1",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "2.5",
HD: " 2.5",
ID: "303475109",
IT: "P83025411-303475109C1-_1_1",
NA: "Under ",
OD: "2/5",
OR: "2",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "3.5",
HD: " 3.5",
ID: "303475112",
IT: "P83025411-303475112C1-_1_1",
NA: "Under ",
OD: "1/8",
OR: "3",
SU: "0"
},
{
type: "PA",
BS: "",
FI: "83025411",
HA: "4.5",
HD: " 4.5",
ID: "303475114",
IT: "P83025411-303475114C1-_1_1",
NA: "Under ",
OD: "1/25",
OR: "4",
SU: "0"
}
]
};
let chars = data["results"];
for (let i = 0, len = chars.length; i < len; i++) {
if (chars[i].type == "MA") {
for (let j = i, len = chars.length; j < len; j++) {
if (chars[j].type == "CO" && chars[j].NA !== "Count : 0") {
for (let k = j + 1, len = chars.length; k < len; k++) {
if (chars[k].type !== "CO") {
var market_name1 = {
name: chars[k].NA,
hader: chars[k].HA,
id: chars[k].OD
};
var markets = [market_name1];
console.log(markets);
}
if (chars[k].type == "CO") {
break;
}
}
}
}
}
}
// Output
// [ { name: 'Over ', hader: '0.5', id: '1/8' } ]
// [ { name: 'Over ', hader: '1.5', id: '4/7' } ]
// [ { name: 'Over ', hader: '2.5', id: '7/4' } ]
// [ { name: 'Over ', hader: '3.5', id: '5/1' } ]
// [ { name: 'Over ', hader: '4.5', id: '12/1' } ]
// [ { name: 'Under ', hader: '0.5', id: '5/1' } ]
// [ { name: 'Under ', hader: '1.5', id: '5/4' } ]
// [ { name: 'Under ', hader: '2.5', id: '2/5' } ]
// [ { name: 'Under ', hader: '3.5', id: '1/8' } ]
// [ { name: 'Under ', hader: '4.5', id: '1/25' } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment