/    Sign up×
Community /Pin to ProfileBookmark

Hey I have this script:

I’m trying to run it on [url]http://www.w3schools.com/js/tryit.asp?filename=tryjs_browser[/url]. I haven’t tried my source yet, but I don’t think it will make a difference (I just want to keep this out of my code until it’s production ready). For some reason if I remove the <b> tags from the output, it comes out garbled.

[CODE]
<script type=”text/javascript”>

function matchParen(str){
num_rp = null;
var count;
for(count=0; num_rp!==0; count++){
if(str[count]=='(‘) ++num_rp;
else if(str[count]==’)’) –num_rp;
}
return count;
}

/*filler stuff for test purposes*/
function Dodec(f){ return true; }
Boolean.prototype.cond = function(q){return !this || q}
k=’a’, x=’b’, y=’d’, n=’k’, r=’k’;
/*filler end*/

ex = “Dodec(k)&#8594;((Dodec(x)&#8594;Dodec(y))&#8594;(Dodec(n)&#8594;Dodec(r)))”;

while(ex.match(‘&#8594;’)){
m = ex.match(/&#8594;.+/).toString();
pos = matchParen(m)+ex.search(‘&#8594;’)+6;
ex = ex.replace(‘&#8594;’,'<b>.cond(</b>’);
ex = ex.substring(0,pos)+'<b>)</b>’+ex.substring(pos);
document.write(ex+”<BR />”);
}
ex = ex.replace(/<.?b>/g,”);

</script>[/CODE]

Also, if you know how to optimize the code that would really be helpful.

Additionally, any other methods on creating a new “operator” would be insightful. I’m just using OO design for now, but I’m trying to create a conditional operator ‘&#8594;’ so that:

[CODE]
P Q P&#8594;Q (Algorithm: !P || Q)
T T T
T F F
F T T
F F T
[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootJun 10.2007 — I haven't tried my source yet, but I don't think it will make a difference [/QUOTE]For some reason if I remove the <b> tags from the output, it comes out garbled.[/QUOTE]
contradiction, you havent tried it yet the output is garbled...
Copy linkTweet thisAlerts:
@dasickisauthorJun 10.2007 — Sorry it was really late I tried it on http://www.w3schools.com/js/tryit.asp?filename=tryjs_browser, but not on my host.

Here's the output with the <b> tags (I changed them to [b] tags so it shows the formatted output):

Dodec(k)[b].cond([/b]((Dodec(x)[b].cond([/b]Dodec(y)[b])[/b])[b].cond([/b](Dodec(n)[b].cond([/b]Dodec(r)[b])[/b])[b])[/b])[b])[/b]



Without the <b> tags:

Dodec(k).cond(((Dodec(x).cond(Dodec(y))&#8594?;(Dodec(n).cond(Dodec(r)))))
Copy linkTweet thisAlerts:
@dasickisauthorJun 10.2007 — I figured it out, it was when I'm adding 6 to the pos variable.

It turns out I needed it for the <b> tags but not when I don't have them.
×

Success!

Help @dasickis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...