私は、一度終了すると基本的な代数方程式を計算するjs関数を持っています。何らかの理由で、配列内の文字列の最初の文字を置き換えることはできません。この関数で以前に使用したことがありますが、現在は機能しません。.replace() と .substring() を使用してみました。
これらは私が試した次のコードです:
// this is what i've been testing it on
// $problem[o][j] = +5
var assi = $problem[0][j].charAt(0); // Get the first character, to replace to opposite sign
switch (assi){
case "+":
console.log($problem[0][j]);
$problem[0][j].replace("+","-");
console.log($problem[0][j]);
break;
}
コンソールへの上記の出力:
> +5
> +5
私が試した次のコード:
// Second code i tried with $problem[0][j] remaining the same
switch(assi){
case "+":
console.log($problem[0][j]);
$problem[0][j].substring(1);
$problem[0][j] = "-" + $problem[0][j];
console.log($problem[0][j]);
break;
}
これにより、コンソールに次のように出力されます。
> +5
> -+5