Skip to content

A lot of work to do pushing just in case #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 106 additions & 2 deletions assets/js/numbers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,107 @@
function compute(expression) {
function compute(expression) {
// TODO - write method definition here
}
var total=0;
var newArray=[];
var number1=0;
var number2=0;

// this function seperates the expression into arrays

function formatArray(expression)
newArray(x)

function formatArray(ex) //creates a new array and pops new numbers into it
{
var number;
var arr=ex.split("");
var counter=1;

for(var i=0;i<arr.length;i++)
{
if(testNumber(arr[i]==true))
{
number+=arr[i]
counter++

}
else{
number=parseInt(number)
newArray.push(number);
if(counter>arr.length)
{
newArray.push(arr[i]);
}
arr.splice(i,counter)
}

}


}
function testNumber(x) //test whole numbers
{
var i=true;
if(i==/\d/.test(x)) //test for whole number using regex
{
return i;
}
else{
return false
}
}

newArray(x)
{


for(var i=0;i<x.length;i++)
{
if(x[i]=="+")
{
var place=0;
number1=parseInt(x[i-1])
number2=parseInt(x[i+1])
total= number1+number2
place=--i
x.splice(place,3)
x.splice(place,0,total);
}
else if(arr[i]=="-")
{
var place=0;
number1=parseInt(x[i-1])
number2=parseInt(x[i+1])
total= number1-number2
place=--i
x.splice(place,3)
x.splice(place,0,total);

}
}

return total;
}

}


// function testArray(x)
// {
// switch(x){
// case "*":

// break;

// case"/":
// break;

// case "+":
// break;

// case "-":
// break;

// default:
// break;
// }
// }