Skip to content

Instantly share code, notes, and snippets.

@manjeshpv
Created October 22, 2014 06:51
Show Gist options
  • Save manjeshpv/047dfdc9aa2eaa3c66df to your computer and use it in GitHub Desktop.
Save manjeshpv/047dfdc9aa2eaa3c66df to your computer and use it in GitHub Desktop.
Solve Linear Equation
function evaluate(x) {
xp = x.split(";")
console.log(xp)
xp.forEach(function (item, index) {
console.log(index)
if (index != 0) {
eval(item)
}
if (index == (xp.length - 1)) {
var ss = (("(" + xp[0]).replace(/(\+|-)/g, ")+(") + ")").replace(/([0-9]+)([a-z]{1})/g, "$1*$2")
console.log(ss)
console.log(eval(ss));
}
})
//Write code here
return x
}evaluate("9a+8b+m-5n+z;a=2;b=0;m=-8;n=24;z=9")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment