简体   繁体   English

JavaScript 数学 Function

[英]JavaScript Math Function

Given an object containing the number of positive and negative reviews, for example { positive: 24, negative: 8 }, return the review positivity score.给定一个包含正面和负面评论数量的 object,例如 {正面:24,负面:8},返回评论正面分数。

function getReviewPositivityScore (positive, negative) {
  let a = positive;
  let b = negative;
  let result = a - b  ;
  return  result;
}

module.exports = getReviewPositivityScore;

Error message I get: getReviewPositivityScore 1) should return the number of positive reviews minus the number of negative reviews我收到的错误消息:getReviewPositivityScore 1) 应该返回正面评论的数量减去负面评论的数量

0 passing (6ms) 1 failing 0 通过 (6ms) 1 失败

  1. getReviewPositivityScore should return the number of positive reviews minus the number of negative reviews: getReviewPositivityScore 应该返回正面评论的数量减去负面评论的数量:

    AssertionError: expected NaN to deeply equal 16 AssertionError:预期 NaN 深度等于 16

    • expected - actual预期 - 实际

    -NaN +16 -NaN +16

    at Context.在上下文。 (.guides/secure/test3.5.1.js:8:17) at processImmediate (internal/timers.js:439:21) (.guides/secure/test3.5.1.js:8:17) 在 processImmediate (internal/timers.js:439:21)

Since you are passing an object you only need one parameter as function input, and then access the values from it:由于您传递的是 object ,因此您只需要一个参数作为 function 输入,然后从中访问值:

function getReviewPositivityScore (object) {
   return object.positive - object.negative;
}

Thanks for the quick help.感谢您的快速帮助。 I was able to solve it.我能够解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM