• 【JS】【codewars】Number of people in the bus


    原题:Number of people in the bus

    There is a bus moving in the city, and it takes and drop some people in each bus stop.

    You are provided with a list (or array) of integer arrays (or tuples). Each integer array has two items which represent number of people get into bus (The first item) and number of people get off the bus (The second item) in a bus stop.

    Your task is to return number of people who are still in the bus after the last bus station (after the last array). Even though it is the last bus stop, the bus is not empty and some people are still in the bus, and they are probably sleeping there :D

    Take a look on the test cases.

    Please keep in mind that the test cases ensure that the number of people in the bus is always >= 0. So the return integer can't be negative.

    The second value in the first integer array is 0, since the bus is empty in the first bus stop.

    翻译:公共汽车上的人数。
    城市里有一辆公交车在行驶,它在每个汽车站接送一些人。

    将为您提供整数数组(或元组)的列表(或数组)。每个整数数组有两个项目,分别表示在公交车站上车的人数(第一个项目)和下车的人数(第二个项目)。

    您的任务是返回在最后一个汽车站之后(在最后一个数组之后)仍在公交车中的人数。即使这是最后一站公交车,公交车也不是空的,车上还有一些人,他们很可能睡在那里:d。

    请看一下测试用例。

    请记住,测试用例确保公交车上的人数始终大于等于0。因此返回整数不能为负。

    第一个整数数组中的第二个值是0,因为第一个公共汽车站中的公交车是空的。

     1 var number = function(busStops){
     2     var upSum=0;
     3     var downSum=0;
     4     for(var i=0; i<busStops.length; i++){
     5       upSum+=busStops[i][0];
     6       downSum+=busStops[i][1];
     7     }   
     8   var last=upSum-downSum;
     9   return last;
    10 }
  • 相关阅读:
    PG中 generate_series函数的使用
    代码搜索神器ag
    效率神器2
    效率神器
    Django-cookie组件
    Django-form组件
    Django组件-分页器
    Django与Ajax
    Django-模型层
    Django-模板层
  • 原文地址:https://www.cnblogs.com/frx2000/p/13663007.html
Copyright © 2020-2023  润新知