嘿,我解决了这个挑战,但是我不明白为什么我不能添加新行?我曾经使用过replace,regex,\ r,\ n和os模块,但没有运气,它确实令人沮丧。有人可以帮我解决这个问题吗?我不确定我缺少什么。我只是想在每个数字之后在新行上呈现此数字数组。
//预期输出
0.500000
0.333333
0.166667
//但得到
['0.333333','0.500000','0.166667']
https://repl.it/@joshuaaguilar20/TruthfulCurvyDaemons
var endOfLine = require('os').EOL;
function plusMinus(arr) {
let obj={
negative:[],
positive:[],
zeros:[]
};
arr.reduce((previous, current, index) => {
if(current == 0){
obj.zeros.push(current)
return previous;
}
if(current > 0 ){
obj.positive.push(current)
++previous;
}
if(current < 0){
obj.negative.push(current)
--previous;
}
return previous;
},0);
let posresult = obj.positive.length / arr.length
obj.positive = posresult.toFixed(6)
let negresult = obj.negative.length / arr.length
obj.negative = negresult.toFixed(6)
let zeroresult = obj.zeros.length / arr.length
obj.zeros = zeroresult.toFixed(6)
let letNewArr = Object.values(obj)
return letNewArr
};