我只是想用javascript比较正确的数字和左数字,这是我的输入样本
matrix C = (1, /// ///
2*sin(0.05*_pi/6), 1, ///
2*sin(-0.45*_pi/6), 2*sin(0.44*_pi/6), 1, ///
2*sin(0.22*_pi/6), 2*sin(0.33*_pi/6), 2*sin(-0.54*_pi/6), 1, ///
2*sin(0.45*_pi/6), 2*sin(0.32*_pi/6), 2*sin(-0.22*_pi/6), 2*sin(-0.13*_pi/6), 1)
matrix B = (40, 26, 13, 146, 0.35)
matrix A = (9, 11, 5, 2, 1)
corr2data var1 var2 var3 var4 var5, n(10000) corr(C) means(B) sds(A) cstorage(lower)
replace var1 = rnormal(var1)
replace var2 = rnormal(var2)
replace var3 = rnormal(var3)
replace var4 = rnormal(var4)
replace var5 = normal(var5)
replace var5 = rbinomial(1,var5)
然后结果是更大的数字:
290|0
290|0
290|2902
250|0
250|0
0|0
0|1299.95
0|1299.95
250|0
290|0
290|0
290|22
32|1299.95
0|0
请帮忙!
答案 0 :(得分:3)
以下是如何做到这一点: -
var input = '290|0\n\
290|0\n\
290|2902\n\
250|0\n\
250|0\n\
0|0\n\
0|1299.95\n\
0|1299.95\n\
250|0\n\
290|0\n\
290|0\n\
290|22\n\
32|1299.95\n\
0|0'
var rows = input.split( '\n' )
var output = [ ]
for (var i = 0; i < rows.length; ++i) {
var row = rows[i]
var parts = row.split( '|' )
if ( 1*parts[0] > 1*parts[1] )
output.push( parts[0] )
else
output.push( parts[1] )
}
output = '\n'.join( output )
答案 1 :(得分:1)
您需要Math.Max()
它将按要求返回最大数量
http://www.w3schools.com/jsref/jsref_max.asp