- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想增加一周中的几天和每天的时间段的值,即早上、下午、晚上和晚上,因为我迭代了一个集合,在那里我得到了时间,然后评估时间在哪个时间段。我需要能够在前端迭代最终结果,但想要一个比我目前所代表的更好的解决方案,但总计数组。有人建议我使用 map ,但不确定如何使用 map 来实现。
var totals = [
// Tot M T W T F S S
[0, 0, 0, 0, 0, 0, 0, 0], // Totals
[0, 0, 0, 0, 0, 0, 0, 0], // Morning
[0, 0, 0, 0, 0, 0, 0, 0], // Afternoon
[0, 0, 0, 0, 0, 0, 0, 0], // Evening
[0, 0, 0, 0, 0, 0, 0, 0] // Night
];
var collectionOfData = entiredataset;
collectionOfData.forEach(function (item) {
var localDate = getLocalDate(item);//gets users local date and determines timeslot id - ie Morning,afternoon, evening, or night
var dayOfWeek = localDate.day();
var timeslotId = item.timeslotId;
totals[timeslotId][dayOfWeek]++; // Increase sessions per slot and day
totals[0][dayOfWeek]++; // Increase total sessions per day
totals[timeslotId][0]++; // Increase total sessions per slot
totals[0][0]++; // Increase total sessions
}
如有任何建议,我们将不胜感激。
最佳答案
我设计数据结构的方法之一如下 - 参见带有输入、输出和总计算方法的演示:
var slots={'Monday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},'Tuesday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},'Wednessday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},'Thursday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},'Friday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},'Saturday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},'Sunday':{'Morning':0,'Afernoon':0,'Evening':0,'Night':0},}
// input data
function insertSlotFor(day, slot) {
slots[day][slot]++;
}
// output data
function getSlotFor(day, slot) {
return slots[day][slot];
}
// get total for a day
function totalForDay(day) {
return Object.keys(slots[day]).reduce(function(prev,curr){
return prev + slots[day][curr];
},0);
}
// get total for a slot
function totalForSlot(slot) {
return Object.keys(slots).reduce(function(prev,curr){
return prev + slots[curr][slot];
},0);
}
insertSlotFor('Monday', 'Morning');
insertSlotFor('Monday', 'Night');
insertSlotFor('Tuesday', 'Morning');
console.log(slots);
console.log(totalForDay('Monday'));
console.log(totalForSlot('Morning'));
.as-console-wrapper{top:0;max-height:100%!important;}
关于javascript - 2D Array 或 Map 以在几天内针对工作日和插槽存储值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40530250/
插槽到底是个啥?5分钟搞定 Vue 插槽 插槽的基本使用 组件使用slot标签,显示组件标签的内容 Title aaa Vu
Closed. This question is not reproducible or was caused by typos。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-to
我有一个对象,它用一个对象发出信号: MyObj *obj = this->generateObj(); emit newObjSignal(obj); delete obj; 我有一个或多个人与此有
距离ETS的发布也有一段时间,也有不少小伙伴通过ETS制作出很多精美的页面,但在我查阅ETS的组件和API中发现,现有版本的ETS并没有插槽的功能。经过一段时间的探索终于找到曲线救国方式实现插槽
我无法找到有关使用资源管理器模板以编程方式向 WebApp 添加插槽的信息/指南。我的基本配置运行良好,创建了 WebApp 本身、SQL 服务器、SQL DB 等,但我也渴望完成插槽,以便我可以将它
我们的项目位于 sitecore 中,并使用 Azure - 应用服务进行部署。我们已经创建了暂存槽,除了应用程序设置和连接字符串之外,还希望使一些配置文件槽特定(交换时坚持槽)。 有没有办法让整个配
我使用 Azure 插槽功能来部署我的机器人: 部署到“暂存”槽 Azure 启动此实例 启动后,我会交换“生产”和“登台”时段 我想在进行插槽之前测试暂存实例,最好使用 Azure 门户中的 Web
我使用 Azure 插槽功能来部署我的机器人: 部署到“暂存”槽 Azure 启动此实例 启动后,我会交换“生产”和“登台”时段 我想在进行插槽之前测试暂存实例,最好使用 Azure 门户中的 Web
我的应用程序只能通过右键单击托盘图标并按“退出”来退出: class DialogUIAg(QDialog): ... self.quitAction = QAction("&Quit
我不太确定如何将其总结为一个谷歌问题,但也许详细解释它会给我更好的帮助。 我正在尝试找到与在 PHP 中的 python 中设置槽的等价物 python : class Node: slots
我浪费了几个小时试图找出这个错误,但我仍然不知道为什么会发生...所以我求助于你! 我将一个对象移动到一个线程中,该线程执行一些工作,完成后会发出一个信号以供 QMainWindow 捕获。就这么简单
我有一个自旋控件 block ,它可以更改数组的各个元素我不想使用单独的接收器槽函数,而是只想指定哪个控件在信号中发送消息 您可以使用 QSignalMapper 来做到这一点——但是是否可以像下面那
我想知道如何将一个单独的变量传递到一个插槽中。我似乎无法让它工作。有什么办法解决这个问题吗? 这是我的代码: QTimer * timer = new QTimer(); connect(timer,
我有一个基类,它定义了一个 Qt 插槽 class Base { public: Base() { connect(otherobject, SIGNAL(mySign
这是基类中声明的样子: protected: void indexAll(); void cleanAll(); 在派生类中,以下不编译: indexAll(); // OK con
比如我有一个函数 void A::fun() { do_1(); emit signal_1(); do_2(); emit signal_2(); do_3(
我希望能够将视频从连接到我的计算机的摄像头直接流式传输到我通过 PCIE 连接到我的计算机的 FPGA。 我不介意使用 javascript 或 C# 等高级语言来执行此操作(因为这些是我知道的具有视
Qt世界中,事件和信号/槽的区别是什么? 一个会取代另一个吗?事件是信号/槽的抽象吗? 最佳答案 Qt documentation可能解释得最好: In Qt, events are objects,
1. 监听属性值的变化 - watch 语法要求:watch里面的函数名必须跟date里面属性名一致 {{num}} 添加 var
在 Class Buttons 中,我有一个 btnRightClicked 信号和一个 mousePressEvent 插槽: void Buttons::mousePressEvent(QMous
我是一名优秀的程序员,十分优秀!