<html>
<head>
<title>Using Javascript Map Object - RJM Programming - August, 2024 ... thanks to https://www.w3schools.com/js/tryit.asp?filename=tryjs_map_groupby and https://medium.com/@sotoer/your-foreach-example-has-the-wrong-order-of-params-which-you-are-also-demonstrating-in-your-sample-42f5491b604e</title>
<style>
td {
vertical-align: top;
}

#demo, #droppable {
background-color: yellow;
}
</style>
<script type=text/javascript>

var m = new Map();
//m.set('b', 2);
//m.set('a', 1);
//m.forEach((k, v, m) => console.log(`key:${k} value:${v} map:${m}`));

var tippingpoint=200;
var tabletds='';
var rspan=1;
var doadd=false;
var text="";
var ddone=false;
var okaytext="These fruits are Ok:<br>";
var lowtext="<br>These fruits are low:<br>";
var lowword="low";
var okayword="ok";
var altered=false;
var thiscont='';

// Fish~`~taylor,300;barramundi,400;perch,100;mullet,234

// Create an Array
var fruits = [
{name:"apples", quantity:300},
{name:"bananas", quantity:500},
{name:"oranges", quantity:200},
{name:"kiwi", quantity:150}
];

// Callback function to select low volumes
function myCallback({ quantity }) {
return (('' + quantity).trim() == '' ? 0 : quantity) > tippingpoint ? okayword : lowword;
}

function mysimpleCallback(qty) {
//alert(qty);
return (('' + qty).trim() == '' ? 0 : qty) > tippingpoint ? okayword : lowword;
}

function process(what) {
document.getElementById('demo').innerHTML=thiscont;
fruits=[];
m = new Map();
alteredstate(document.getElementById('demo'), true);
return thiscont;
}

function andthendo(inthing) {
document.getElementById('thname').innerHTML=location.search.split('thname=')[1] ? decodeURIComponent(location.search.split('thname=')[1].split('&')[0].split('#')[0]) : document.getElementById('thname').innerHTML;
document.getElementById('thquantity').innerHTML=location.search.split('thquantity=')[1] ? decodeURIComponent(location.search.split('thquantity=')[1].split('&')[0].split('#')[0]) : document.getElementById('thquantity').innerHTML;
document.getElementById('topic').innerHTML=location.search.split('topic=')[1] ? decodeURIComponent(location.search.split('topic=')[1].split('&')[0].split('#')[0]) : document.getElementById('topic').innerHTML;
document.getElementById('threport').innerHTML=location.search.split('threport=')[1] ? decodeURIComponent(location.search.split('threport=')[1].split('&')[0].split('#')[0]) : document.getElementById('threport').innerHTML;
return inthing;
}

function moreencodeURIComponent(intodo) {
var indemo=null;
outstuff=encodeURIComponent(intodo);
indemo=document.getElementById('thname');
if (outstuff == '') {
outstuff+='?thname=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&thname=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
indemo=document.getElementById('thquantity');
if (outstuff == '') {
outstuff+='?thquantity=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&thquantity=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
indemo=document.getElementById('topic');
if (outstuff == '') {
outstuff+='?topic=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&topic=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
indemo=document.getElementById('threport');
if (outstuff == '') {
outstuff+='?threport=' + encodeURIComponent(('' + (indemo.innerHTML)))
} else {
outstuff+='&threport=' + encodeURIComponent(('' + (indemo.innerHTML)))
}
return outstuff;
}

function alteredstate(indemo, readd) {
var reprecs=[], ireprecs=0, recwords=[];
//alert(('' + (indemo.innerText | indemo.contentWindow | indemo.contentDocument)) + ' vs ' + indemo.innerHTML);
var theses=('' + (indemo.innerHTML)).split('These ');
if (eval('' + theses.length) == 3) {
if (theses[1].indexOf(':') != -1 && theses[2].indexOf(':') != -1) {
altered=true;
okaytext='These ' + theses[1].split(':')[0] + ':<br>';
lowtext='<br>These ' + theses[2].split(':')[0] + ':<br>';
if (theses[1].indexOf(' are ') != -1) {
//alert('Yes ' + okaytext);
document.getElementById('topic').innerHTML=theses[1].split(' are ')[0].substring(0,1).toUpperCase() + theses[1].split(' are ')[0].substring(1).toLowerCase().replace(/s$/g,'');
okayword=theses[1].split(' are ')[1].split(':')[0].toLowerCase();
document.getElementById('spanok').innerHTML=theses[1].split(' are ')[1].split(':')[0];
document.getElementById('itip').step=0.001;
if (('' + readd).replace(/^undefined$/g, '') != '') {
// alert('yes ' + okaytext.replace('These ','') + ' RE ' + theses[1]);
//alert(theses[1].split(okaytext.replace('These ',''))[1].split('<br>These ')[0]);
reprecs=theses[1].split(okaytext.replace('These ',''))[1].split('<br>These ')[0].split('<br>');
for (ireprecs=0; ireprecs<reprecs.length; ireprecs++) {
recwords=reprecs[ireprecs].split(' ');
if (eval('' + recwords.length) > 1) {
if (reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim() != '') {
//alert('ok: ' + reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim());
addone(reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim(), recwords[eval(-1 + recwords.length)]);
}
}
}
}
}
if (theses[2].indexOf(' are ') != -1) {
document.getElementById('topic').innerHTML=theses[2].split(' are ')[0].substring(0,1).toUpperCase() + theses[2].split(' are ')[0].substring(1).toLowerCase().replace(/s$/g,'');
lowword=theses[2].split(' are ')[1].split(':')[0].toLowerCase();
document.getElementById('spanlow').innerHTML=theses[2].split(' are ')[1].split(':')[0];
document.getElementById('itip').step=0.001;
if (('' + readd).replace(/^undefined$/g, '') != '') {
reprecs=theses[2].split(lowtext.replace('<br>These ',''))[1].split('<br>');
for (ireprecs=0; ireprecs<reprecs.length; ireprecs++) {
recwords=reprecs[ireprecs].split(' ');
if (eval('' + recwords.length) > 1) {
if (reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim() != '') {
//alert('low: ' + reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim());
addone(reprecs[ireprecs].replace(' ' + recwords[eval(-1 + recwords.length)], '').replace('' + recwords[eval(-1 + recwords.length)], '').trim(), recwords[eval(-1 + recwords.length)]);
}
}
}
}
}
}
}
if (('' + readd).replace(/^undefined$/g, '') != '') {
document.getElementById('itip').value=location.search.split('tippingvalue=')[1] ? andthendo(decodeURIComponent(location.search.split('tippingvalue=')[1].split('&')[0].split('#')[0])) : document.getElementById('itip').value;
tippingpoint=eval('' + document.getElementById('itip').value);
beadjustable();
}
}

function addone(knownname, knownquantity) {
doadd=true;
//alert(knownname);
//alert(knownquantity);
if (('' + knownname) != 'undefined' && ('' + knownquantity) != 'undefined') {
fruits.push({name:knownname, quantity:knownquantity});
m.set(knownname, knownquantity);
} else if (('' + knownname) != 'undefined') {
fruits.push({name:knownname, quantity:0});
m.set(knownname, 0);
} else {
fruits.push({name:"", quantity:0});
m.set('', 0);
}
doadd=false;
beadjustable();
}

function fix(tdo) {
var idx=0, needto=true;
if (tdo.id.indexOf('tdname') == 0) {
if (tdo.id != 'tdname') { idx=eval(('' + tdo.id).substring(6)); }
fruits[idx].name=('' + (tdo.innerHTML));
if (m.has("")) {
m.delete("");
m.set(fruits[idx].name, fruits[idx].quantity);
tdo.setAttribute('contenteditable', false);
}
if (needto) { beadjustable(); }
} else {
if (tdo.id != 'tdquantity') { idx=eval(('' + tdo.id).substring(10)); }
//alert(tdo.outerHTML);
//alert('idx=' + idx + ' and ' + ('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument)) + ' and fruits[idx].name=' + fruits[idx].name);
if (m.has(fruits[idx].name)) {
if (('' + fruits[idx].quantity) == ('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument))) { needto=false; }
}
if (needto) {
fruits[idx].quantity=('' + (tdo.innerText | tdo.contentWindow | tdo.contentDocument));
if (m.has(fruits[idx].name)) {
m.set(fruits[idx].name, fruits[idx].quantity);
}
}
if (needto) { beadjustable(); }
}
}

function thecall() {
var kk=0;

// Group by ok and low
if (altered) {
text=okaytext;
} else {
text="These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are Ok:<br>";
}
try {
const result = Map.groupBy(fruits, myCallback);

// Display Results
try {
for (let x of result.get(okayword)) {
if (x.name != '' || x.quantity != 0) {
text += "" + x.name + " " + x.quantity + "<br>";
}
if (!m.has(x.name)) {
m.set(x.name, x.quantity);
}
}
} catch(ebad) { }
if (altered) {
text+=lowtext;
} else {
text += "<br>These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are low:<br>";
}
try {
for (let x of result.get(lowword)) {
if (x.name != '' || x.quantity != 0) {
text += "" + x.name + " " + x.quantity + "<br>";
}
if (!m.has(x.name)) {
m.set(x.name, x.quantity);
}
}
console.log(result.get(okayword));
} catch(ebad) { }
} catch(overebad) {
if (altered) {
text=okaytext;
} else {
text="These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are Ok:<br>";
}
for (kk=0; kk<fruits.length; kk++) {
if (('' + fruits[kk].quantity).replace('-','').substring(0,1) >= '0' && ('' + fruits[kk].quantity).replace('-','').substring(0,1) <= '9') {
if (mysimpleCallback(fruits[kk].quantity) == 'ok') {
//alert(fruits[kk].name);
text += "" + fruits[kk].name + " " + fruits[kk].quantity + "<br>";
//alert('2:' + fruits[kk].name);
if (!m.has(fruits[kk].name)) {
//alert('3:' + fruits[kk].name);
m.set(fruits[kk].name, fruits[kk].quantity);
//alert('4:' + fruits[kk].name);
}
}
}
}
if (altered) {
text+=lowtext;
} else {
text += "<br>These " + document.getElementById('topic').innerHTML.toLowerCase() + "s are low:<br>";
}
for (kk=0; kk<fruits.length; kk++) {
if (('' + fruits[kk].quantity).replace('-','').substring(0,1) >= '0' && ('' + fruits[kk].quantity).replace('-','').substring(0,1) <= '9') {
if (mysimpleCallback(fruits[kk].quantity) == 'low') {
text += "" + fruits[kk].name + " " + fruits[kk].quantity + "<br>";
if (!m.has(fruits[kk].name)) {
m.set(fruits[kk].name, fruits[kk].quantity);
}
}
}
}

}
document.getElementById("demo").innerHTML = text;

}

function consolelog(inrec) {
if (rspan == 0) {
document.getElementById("tdname").innerHTML=inrec.split('value:')[1].split(' key:')[0].split(' map:')[0];
document.getElementById("tdquantity").innerHTML=inrec.split('key:')[1].split(' value:')[0].split(' map:')[0];
rspan=1;
} else if (inrec.split('value:')[1].split(' key:')[0].split(' map:')[0] == '') {
tabletds+='<tr><td contenteditable=true id=tdname' + rspan + ' onblur=fix(this);>' + inrec.split('value:')[1].split(' key:')[0].split(' map:')[0] + '</td><td contenteditable=true id=tdquantity' + rspan + ' onblur=fix(this);>' + inrec.split('key:')[1].split(' value:')[0].split(' map:')[0] + '</td></tr>';
rspan++;
} else {
tabletds+='<tr><td contenteditable=false id=tdname' + rspan + ' onblur=fix(this);>' + inrec.split('value:')[1].split(' key:')[0].split(' map:')[0] + '</td><td contenteditable=true id=tdquantity' + rspan + ' onblur=fix(this);>' + inrec.split('key:')[1].split(' value:')[0].split(' map:')[0] + '</td></tr>';
rspan++;
}
//alert(inrec);
if (doadd) {
fruits.push({name:"", quantity:0});
m.set('', 0);
tabletds+='<tr><td contenteditable=true id=tdname' + rspan + ' onblur=fix(this);></td><td contenteditable=true id=tdquantity' + rspan + ' onblur=fix(this);>0</td></tr>';
rspan++;
doadd=false;
}
}

function dragElement(elmnt) { // thanks to https://www.w3schools.com/howto/howto_js_draggable.asp
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "header")) {
// if present, the header is where you move the DIV from:
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
// otherwise, move the DIV from anywhere inside the DIV:
elmnt.onmousedown = dragMouseDown;
}

function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}

function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
alert('Here');
}

function closeDragElement() {
// stop moving when mouse button is released:
document.onmouseup = null;
document.onmousemove = null;
}
}


function allowDrop(ev) { // thanks to https://www.w3schools.com/html/html5_draganddrop.asp
ev.preventDefault();
}

function drag(ev) { // thanks to https://www.w3schools.com/html/html5_draganddrop.asp
ev.dataTransfer.setData("text", ev.target.id);
}

function doemail(data) {
var a=null;
a = document.createElement("a");
var contis=(document.getElementById('demo').innerText || document.getElementById('demo').contentWindow || document.getElementById('demo').contentDocument);
var topicis=(document.getElementById('topic').innerText || document.getElementById('topic').contentWindow || document.getElementById('topic').contentDocument);
var subjis=(document.getElementById('threport').innerText || document.getElementById('threport').contentWindow || document.getElementById('threport').contentDocument);
a.href='mailto:?subject=' + encodeURIComponent(topicis) + '%20' + encodeURIComponent(subjis) + '&body=' + encodeURIComponent(document.URL.split('?')[0].split('#')[0] + '?tippingvalue=' + moreencodeURIComponent(document.getElementById('itip').value) + '#data=') + encodeURIComponent(encodeURIComponent(contis.replace(/\<bJUNKr\>/g, String.fromCharCode(10))));
a.click();
}

function dosms(data) {
var a=null;
a = document.createElement("a");
var contis=(document.getElementById('demo').innerText || document.getElementById('demo').contentWindow || document.getElementById('demo').contentDocument);
var topicis=(document.getElementById('topic').innerText || document.getElementById('topic').contentWindow || document.getElementById('topic').contentDocument);
a.href='sms:&body=' + encodeURIComponent(document.URL.split('?')[0].split('#')[0] + '?tippingvalue=' + moreencodeURIComponent(document.getElementById('itip').value) + '#data=') + encodeURIComponent(encodeURIComponent(contis.replace(/\<bJUNKr\>/g, String.fromCharCode(10))));
a.click();
}

function drop(ev) { // thanks to https://www.w3schools.com/html/html5_draganddrop.asp
var ssrect=null, isemail=true, a=null;
ssrect=document.getElementById('droppable').getBoundingClientRect();
if (eval(ssrect.right - ev.clientX) < eval(ev.clientX - ssrect.left)) { isemail=false; }
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
if (isemail) {
//a = document.createElement("a");
//a.href='mailto:?subject=' + encodeURIComponent(document.getElementById('topic').innerHTML) + '%20Report%20of%20Inventory&body=' + encodeURIComponent(document.getElementById(data).innerHTML.replace(/\<bJUNKr\>/g, String.fromCharCode(10)));
//a.click();
doemail(data);
} else if (!isemail) {
//a = document.createElement("a");
//a.href='sms:&body=' + encodeURIComponent(document.getElementById(data).innerHTML.replace(/\<bJUNKr\>/g, String.fromCharCode(10)));
//a.click();
dosms(data);
} else {
ev.target.appendChild(document.getElementById(data));
}
}

function beadjustable() {
var srect=null;
var tpis=location.search.split('tippingvalue=')[1] ? andthendo(decodeURIComponent(location.search.split('tippingvalue=')[1].split('&')[0].split('#')[0])) : document.getElementById('itip').value;
if (!ddone) {
ddone=true;
if (('' + location.hash).indexOf('#data') == 0) {
thiscont=decodeURIComponent(('' + location.hash).substring(5).replace(/^\=/g,'').replace(/^\%3d/g,'').replace(/^\%3D/g,'').replace(/\%0A/g,encodeURIComponent('<br>')));
setTimeout(function(){ document.getElementById('demo').innerHTML=process(decodeURIComponent(('' + location.hash).substring(5).replace(/^\=/g,'').replace(/^\%3d/g,'').replace(/^\%3D/g,'').replace(/\%0A/g,encodeURIComponent('<br>')))); }, 3000);
}
srect=document.getElementById('droppable').getBoundingClientRect();
document.getElementById('droppable').style.border='1px pink dotted';
document.getElementById('droppable').style.position='absolute';
document.getElementById('droppable').style.top='' + srect.top + 'px';
document.getElementById('droppable').style.left='' + srect.left + 'px';
// Make the DIV element draggable ... thanks to https://www.w3schools.com/howto/howto_js_draggable.asp
dragElement(document.getElementById('droppable'));
}
tippingpoint=eval('' + document.getElementById('itip').value);
document.getElementById("mysup").title='Add an editable ' + document.getElementById('topic').innerHTML.toLowerCase();
thecall();
tabletds='';
rspan=0;
m.forEach((k, v, m) => consolelog(`key:${k} value:${v} map:${m}`));
document.getElementById("thd").innerHTML = document.getElementById("thd").innerHTML.split(document.getElementById("demo").innerHTML)[0] + document.getElementById("demo").innerHTML + '</td></tr>' + tabletds;
document.getElementById("demo").rowSpan = rspan;
document.getElementById("tdtip").rowSpan = rspan;
document.getElementById('itip').value = tippingpoint;
if (tpis != tippingpoint) {
setTimeout(function(){
document.getElementById('itip').value=location.search.split('tippingvalue=')[1] ? andthendo(decodeURIComponent(location.search.split('tippingvalue=')[1].split('&')[0].split('#')[0])) : document.getElementById('itip').value;
tippingpoint=eval('' + document.getElementById('itip').value);
beadjustable();
}, 2000);
}
ddone=true;
}

function askall(preenterall) {
var isfirst=true;
var delall=false;
var enterall=('' + preenterall).replace(/^undefined$/g,'');
if (enterall == '') {
enterall=prompt('Optionally copy all your CSV (comma separated values) data to apply here (where ; or | can be record delimiters). Optionally prefix this CSV data with your topic followed by ~`~' + String.fromCharCode(10) + String.fromCharCode(10) + 'Example ...' + String.fromCharCode(10) + 'Fish~`~taylor,300;barramundi,400;perch,100;mullet,234', '');
} //else {
//alert(enterall);
//}
if (enterall == null) { enterall=''; }
if (enterall.indexOf('~`~') != -1) { document.getElementById('topic').innerHTML=enterall.split('~`~')[0]; enterall=enterall.replace(enterall.split('~`~')[0] + '~`~', ''); }
if (enterall.indexOf(',') != -1) {
var elines=[];
if (enterall.indexOf(String.fromCharCode(10)) != -1) {
elines=enterall.split(String.fromCharCode(10));
} else if (enterall.indexOf(';') != -1) {
elines=enterall.split(';');
} else if (enterall.indexOf('|') != -1) {
elines=enterall.split('|');
}
for (var ie=0; ie<elines.length; ie++) {
if (elines[ie].indexOf('","') != -1 && elines[ie].indexOf('","') < elines[ie].indexOf(',')) {
if (!delall) {
delall=true;
fruits=[];
m = new Map();
}
if (elines[ie].substring(1).replace('-','').substring(0,1) >= '0' && elines[ie].substring(1).replace('-','').substring(0,1) <= '9') {
//alert(1);
addone(elines[ie].split('","')[1].split('"')[0], elines[ie].substring(1).split('"')[0]);
} else {
//alert(2);
addone(elines[ie].substring(1).split('"')[0], elines[ie].split('","')[1].split('"')[0]);
}
} else if (elines[ie].indexOf('",') != -1 && elines[ie].indexOf('",') < elines[ie].indexOf(',')) {
if (!delall) {
delall=true;
fruits=[];
m = new Map();
}
if (elines[ie].substring(1).replace('-','').substring(0,1) >= '0' && elines[ie].substring(1).replace('-','').substring(0,1) <= '9') {
//alert(3);
addone(elines[ie].split('",')[1].split(',')[0], elines[ie].substring(1).split('"')[0]);
} else {
//alert(4);
addone(elines[ie].substring(1).split('"')[0], elines[ie].split('",')[1].split(',')[0]);
}
} else if (elines[ie].indexOf(',"') != -1 && elines[ie].indexOf(',"') == elines[ie].indexOf(',')) {
if (!delall) {
delall=true;
fruits=[];
m = new Map();
}
if (elines[ie].substring(0).replace('-','').substring(0,1) >= '0' && elines[ie].substring(0).replace('-','').substring(0,1) <= '9') {
//alert(5);
addone(elines[ie].split(',"')[1].split('"')[0], elines[ie].substring(0).split(',')[0]);
} else {
//alert(6);
addone(elines[ie].substring(0).split(',')[0], elines[ie].split(',"')[1].split('"')[0]);
}
} else if (elines[ie].indexOf(',') != -1) {
if (!delall) {
delall=true;
fruits=[];
m = new Map();
}
if (elines[ie].substring(0).replace('-','').substring(0,1) >= '0' && elines[ie].substring(0).replace('-','').substring(0,1) <= '9') {
//alert(7);
addone(elines[ie].substring(0).split(',')[1], elines[ie].substring(0).split(',')[0]);
} else {
//alert(8);
if (isfirst && ((elines[ie].substring(0).split(',')[1] + ' ').replace('-','').substring(0,1) < '0' || (elines[ie].substring(0).split(',')[1] + ' ').replace('-','').substring(0,1) > '9')) {
document.getElementById('topic').innerHTML=elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1);
document.getElementById('thname').innerHTML=elines[ie].substring(0).split(',')[0].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[0].substring(1);
document.getElementById('thquantity').innerHTML=elines[ie].substring(0).split(',')[1].substring(0,1).toUpperCase() + elines[ie].substring(0).split(',')[1].substring(1);
} else {
addone(elines[ie].substring(0).split(',')[0], elines[ie].substring(0).split(',')[1]);
}
}
}
isfirst=false;
}
beadjustable();
}
}

function extractContent(s, space) { // thanks to https://stackoverflow.com/questions/28899298/extract-the-text-out-of-html-string-using-javascript
var xmlret='';
if (s.split('>')[0].indexOf('xml') != -1 && eval('' + s.split('>').length) > 1) {
var innards=s.split('>');
for (var iri=1; iri<innards.length; iri++) {
xmlret+=innards[iri].split('<')[0];
}
return xmlret;
}
var span= document.createElement('span');
span.innerHTML= s;
if (space) {
var children= span.querySelectorAll('*');
for(var i = 0 ; i < children.length ; i++) {
if(children[i].textContent)
children[i].textContent+= ' ';
else
children[i].innerText+= ' ';
}
}
return [span.textContent || span.innerText].toString().replace(/ +/g,' ');
}

function yesthreethree(restis) {
if (restis.indexOf(';base64,') != -1) {
var icontent=window.atob(restis.split(';base64,')[1]);
if ((('' + icontent).trim() + ' ').replace(/^\[caption/g,'<').substring(0,1) == '<') {
askall(extractContent(icontent,true));
} else {
askall(icontent);
}
} else {
askall(restis);
}
}


</script>
</head>
<body onload='beadjustable();'>
<h1 title='Can browse for incoming CSV style input data (of your inventory) with Choose File button' style=height:80px;overflow-y:hidden;>Arrays and Maps <iframe title='Can browse for incoming CSV style input data (of your inventory) here' class="spag" scrolling="no" data-onload="iifopen(this);" id="cbi" frameborder="0" style="width:173px;height:218px;margin-top:-204px;" src="/HTMLCSS/client_browsing.htm?totype=csv&d=1989786754"></iframe> <span style='font-size:12px;display:inline-block;' ondrop="drop(event);" ondragover="allowDrop(event);" title='You can drag CSV inventory data to here as required to Email or SMS report' id=droppable><span onclick=doemail('demo');>📧 </span><span onclick=dosms('demo');> 📟</span></span> </h1>
<h3>RJM Programming - August, 2024 ... thanks to https://www.w3schools.com/js/tryit.asp?filename=tryjs_map_groupby and https://medium.com/@sotoer/your-foreach-example-has-the-wrong-order-of-params-which-you-are-also-demonstrating-in-your-sample-42f5491b604e</h3>
<br>
<table id=mytable border=20 style="width:80%;" cellpadding=10 cellspacing=10>
<thead id=thd>
<tr><th colspan=4><span title='Double click to be able to enter CSV data' id=topic contenteditable=true onblur=beadjustable(); ondblclick=askall();>Fruit</span> Report <sup id=mysup style=cursor:pointer; title='Add an editable fruit' onclick=addone();>++</sup></th></tr>
<tr><th id=thname contenteditable=true>Name</th><th id=thquantity contenteditable=true>Quantity</th><th>Tipping Value</th><th id=threport contenteditable=true><span id=spanok>Ok</span> versus <span id=spanlow>Low</span> Report</th></tr>
<tr><td id=tdname contenteditable=false onblur=fix(this);></td><td id=tdquantity contenteditable=true onblur=fix(this);></td><td id=tdtip rowspan=1><input style=width:98%; onblur="tippingpoint=eval('' + this.value); beadjustable();" onchange="tippingpoint=eval('' + this.value); beadjustable();" type=number id=itip step=1 value=200 data-min=0></input></td><td onblur=alteredstate(this); contenteditable=true draggable="true" ondragstart="drag(event);" id=demo rowspan=1></td></tr>
</thead>
<tbody id=tbd>
</tbody>
</table>
<input type=hidden id=cfrom value=''></input><input type=hidden id=cto value=''></input><input type=hidden id=outputname value=''></input><input type=hidden id=thewords value=''></input><input type=hidden id=saysub value=''></input><input type=hidden id=resultout value=''></input><input type=hidden id=resJUNKult value=''></input><input type=hidden id=audioname value=''></input>
</body>
</html>