Skip to content

Commit

Permalink
fix(javascript-calculator): adjust minus unicode, add noreferrer (#376)
Browse files Browse the repository at this point in the history
* minus oper showing as zero fixed / rel tag

* 6 or more +0 and neg num fix
  • Loading branch information
Dave2188 authored Feb 18, 2023
1 parent fa29f99 commit 3ab3322
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions apps/javascript-calculator/client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const projectName = 'javascript-calculator';
// coded by @no-stack-dub-sack (github) / @no_stack_sub_sack (codepen)

// VARS:
const isOperator = /[x/+]/,
endsWithOperator = /[x+/]$/,
endsWithNegativeSign = /\d[x/+]{1}$/,
const isOperator = /[x/+-]/,
endsWithOperator = /[x+-/]$/,
endsWithNegativeSign = /\d[x/+-]{1}-$/,
clearStyle = { background: '#ac3939' },
operatorStyle = { background: '#666666' },
equalsStyle = {
Expand Down Expand Up @@ -59,18 +59,17 @@ class Calculator extends React.Component {
}
expression = expression
.replace(/x/g, '*')
.replace(//g, '-')
.replace('--', '+0+0+0+0+0+0+');
.replace(/-/g, '-')
.replace('--', '-');
let answer = Math.round(1000000000000 * eval(expression)) / 1000000000000;
this.setState({
currentVal: answer.toString(),
formula:
expression
.replace(/\*/g, '⋅')
.replace(/-/g, '‑')
.replace('+0+0+0+0+0+0+', '‑-')
.replace(/(x|\/|\+)/, '$1-')
.replace(/^/, '-') +
.replace(/-/g, '-')
.replace(/(x|\/|\+)-/, '$1-')
.replace(/^-/, '-') +
'=' +
answer,
prevVal: answer,
Expand All @@ -97,7 +96,7 @@ class Calculator extends React.Component {
(endsWithNegativeSign.test(formula + value) ? formula : prevVal) +
value
});
} else if (value !== '') {
} else if (value !== '-') {
this.setState({
formula: prevVal + value
});
Expand Down Expand Up @@ -195,7 +194,7 @@ class Calculator extends React.Component {
<div className='author'>
{' '}
Designed and Coded By <br />
<a href='https://goo.gl/6NNLMG' target='_blank'>
<a href='https://goo.gl/6NNLMG' target='_blank' rel='noreferrer'>
Peter Weinberg
</a>
</div>
Expand Down Expand Up @@ -246,9 +245,9 @@ class Buttons extends React.Component {
id='subtract'
onClick={this.props.operators}
style={operatorStyle}
value=''
value='-'
>
-
</button>
<button id='four' onClick={this.props.numbers} value='4'>
4
Expand Down

0 comments on commit 3ab3322

Please sign in to comment.