消除结果 [英] eliminate results

查看:66
本文介绍了消除结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


我从数据库收到可变数量的结果。


在我的页面中,我可以显示最多36结果。


我想整洁地消除超出的结果。


例如:

说,我们有40个结果。

我必须消除4个结果。

- >我绝不能消除第一个和最后一个。


所以,我有:

34-4 = 30;

30/4返回7,5(舍入= 7);


要消除的元素将是:

7,14,21,28


我必须自动执行此程序...


我尝试了以下解决方案:


//用于测试目的的硬编码结果数

totResults = 150;

//最大项目数

maxItems = 36;

//

p = totResults / maxItems;

//

temp = [];

for(i = 0; i< maxItems + 1; i ++){

temp [Math.ceil(p * i)] = Math.ceil(p * i) );


}


未定义元素的创建完全适用于我的

目的,所以请不要不用担心。


T.事实上,这个algorhitm在一定数量的情况下起作用,但

有时它不会因为四舍五入问题而受到影响。


有人可以帮我吗?谢谢!

Hello.

I receive from a database a variable number of results.

In my page, I can show a maximum of 36 results.

I want to "neatly" eliminate the exceeding results.

For example:
say, we have 40 results.
I must eliminate 4 results.
-->I must never eliminate the first and the last.

So, I have:
34-4=30;
30/4 returns 7,5 (rounded = 7);

the elements to eliminate will be:
7, 14, 21, 28

I must automate this procedure...

I tried the following solution:

// hardcoded number of results for testing purposes
totResults = 150;
// maximum number of items
maxItems = 36;
//
p = totResults/maxItems;
//
temp = [];
for (i=0; i<maxItems+1; i++) {
temp[Math.ceil(p*i)] = Math.ceil(p*i);

}

The creation of undefined elements is perfectly functional to my
purposes, so please don''t worry about it.

The fact is that this algorhitm works in a certain number of cases but
sometimes it doesn''t, dued to rounding issues.

Could someone help me? Thanks!

推荐答案

写于2008年7月26日comp.lang.javascript
wrote on 26 jul 2008 in comp.lang.javascript:

您好。


我从数据库收到可变数量的结果。
Hello.

I receive from a database a variable number of results.



似乎是我的学校作业。


Seems school assignment to me.


在我的页面中,我可以展示一个最多36个结果。


我想整洁地消除超出的结果。


例如:

说,我们有40个结果。

我必须消除4个结果。

- >我绝不能消除第一个和最后一个。


所以,我有:

34-4 = 30;

30/4返回7,5(舍入= 7);


要消除的元素将是:

7,14,21,28


我必须自动执行此程序...


我尝试了以下解决方案:


//用于测试目的的硬编码结果数

totResults = 150;

//最大项目数

maxItems = 36;

//

p = totResults / maxItems;

//

temp = [];

for(i = 0; i< maxItems + 1; i ++){

temp [Math.ceil(p * i)] = Math.ceil(p * i) );

}

未定义元素的创建完全适用于我的

目的,所以请不要担心关于它。


事实是这个algorhitm在一定数量的情况下起作用,但

有时它不会因为四舍五入问题而受到影响。


有人可以帮我吗?谢谢!
In my page, I can show a maximum of 36 results.

I want to "neatly" eliminate the exceeding results.

For example:
say, we have 40 results.
I must eliminate 4 results.
-->I must never eliminate the first and the last.

So, I have:
34-4=30;
30/4 returns 7,5 (rounded = 7);

the elements to eliminate will be:
7, 14, 21, 28

I must automate this procedure...

I tried the following solution:

// hardcoded number of results for testing purposes
totResults = 150;
// maximum number of items
maxItems = 36;
//
p = totResults/maxItems;
//
temp = [];
for (i=0; i<maxItems+1; i++) {
temp[Math.ceil(p*i)] = Math.ceil(p*i);

}

The creation of undefined elements is perfectly functional to my
purposes, so please don''t worry about it.

The fact is that this algorhitm works in a certain number of cases but
sometimes it doesn''t, dued to rounding issues.

Could someone help me? Thanks!




-

Evertjan。

荷兰。

(请将x''es更改为我的电子邮件地址中的点数)



--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


ch ******** @ gmail.com 写道:

我从数据库收到可变数量的结果。


在我的页面中,我最多可以显示36个结果。


我想整洁地消除超出的结果。

[...]

我尝试了以下解决方案:


//硬编码的结果数量用于测试目的

totResults = 150;

//最大物品数

maxItems = 36;

/ /

p = totResults / maxItems;

//

temp = [];

for(i = 0 ; i< maxItems + 1; i ++){

temp [Math.ceil(p * i)] = Math.ceil(p * i);

}


未定义元素的创建完全适用于我的

目的,所以请不要担心。


事实上,这个algorhitm在一定数量的情况下起作用,但

有时它不会因为四舍五入问题而受到影响。


可能有人帮我?谢谢!
I receive from a database a variable number of results.

In my page, I can show a maximum of 36 results.

I want to "neatly" eliminate the exceeding results.
[...]
I tried the following solution:

// hardcoded number of results for testing purposes
totResults = 150;
// maximum number of items
maxItems = 36;
//
p = totResults/maxItems;
//
temp = [];
for (i=0; i<maxItems+1; i++) {
temp[Math.ceil(p*i)] = Math.ceil(p*i);
}

The creation of undefined elements is perfectly functional to my
purposes, so please don''t worry about it.

The fact is that this algorhitm works in a certain number of cases but
sometimes it doesn''t, dued to rounding issues.

Could someone help me? Thanks!



var trimmedResults = temp.slice(start,start + 36);

PointedEars

- < br $>
var bugRiddenCrashPronePieceOfJunk =(

navigator.userAgent.indexOf(''MSIE 5'')!= -1

&& navigator。 userAgent.indexOf(''Mac'')!= -1

)// Plone,register_function.js:16

var trimmedResults = temp.slice(start, start + 36);
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf(''MSIE 5'') != -1
&& navigator.userAgent.indexOf(''Mac'') != -1
) // Plone, register_function.js:16



* var trimmedResults = temp.slice(start,start + 36);
* var trimmedResults = temp.slice(start, start + 36);




您好,感谢您的回复。

事实上,temp将包含超过36个结果:

许多结果将是未定义的,我需要它们。

通过修剪该阵列的方式,我将无法获得预期的

无论如何,非常感谢。



Hi, and thanks for your kind reply.
The fact is that temp will contain more than 36 results:
many results will be undefined and I need them as they are.
By trimming that array the way you do I will not get the expected
result.
Anyway, thanks very much.


这篇关于消除结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆