问题标签 [remove-if]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
39 浏览

javascript - 即使 innerHTML 不匹配,记忆游戏也会删除任何 div

我正在创建一个基本的记忆游戏。如果第一个单击的 div 的 innerHTML 与第二个匹配,我想删除 div,但由于某种原因,无论单击哪两个 div,它都会删除 div。我该如何解决这个问题?

0 投票
3 回答
6874 浏览

c++ - 从数组中删除所有大于 n 的元素

我是编程初学者。有些东西给我编码带来了麻烦。假设,我有一个数组。

我想删除所有大于 9 的元素。我该怎么做?

0 投票
1 回答
54 浏览

php - 如果不包含数组的一部分,则删除它

我在 php 中有一个名为 $json 的数组。看起来像这样

如何删除 GAME != "Counter-Strike: Global Offensive" 的数组的一部分?

0 投票
1 回答
1683 浏览

java - 如何创建一个从另一个类中获取随机值的方法?

我试图从另一个类中随机获取整数,但无法弄清楚如何获取这些值。第一类是我的初始随机数生成器。第二类是我要检索这些数字的类。我创建了一个抓取方法,但无法弄清楚如何从类 ArrayBag 中检索这些随机整数。任何帮助,将不胜感激!

0 投票
0 回答
139 浏览

list - 在 remove_if 中为对象列表包含更多参数

如果这是一个平凡的问题,我深表歉意,但我很难找到一个明确的答案。我有一个称为事件的用户定义对象列表,它又是事件模拟的一部分。我想从列表中删除具有其成员之一(类型)的特定值的对象,该成员由用户动态提供。到目前为止我得到的相关代码(在删除所有对“a”的引用之后,它与常量一起使用):

我认为问题在于无法使用 remove_if 函数传递变量“a”;它应该只有一个参数,而不是两个。你对如何处理这个问题有什么建议吗?

先感谢您!

0 投票
1 回答
650 浏览

c++ - In c++, is it safe to use std::numeric_limits::max() as a special "flag"?

Given

where ind is 1sorted in ascending order.

I want to do the equivalent of the following:

I came up with this:

This is very fast, but it doesn't feel right to use the std::numeric_limits::max() as a flag in this context.

Of course feelings shouldn't play too much into the equation ... clearly comparing the doubles within the std::remove is safe, and the limit will never occur in practice in this vector in a working application, so it should be ok, no?

Any thoughts on this?


1) Ref comment by the OP. – Alf

0 投票
0 回答
48 浏览

java - 删除循环中的元素后迭代器的排序

在我的代码中,我编写了一个函数来获取一个特定商店的所有条目。我的查询返回所有条目,在这些条目中迭代后,我使用导入参数状态删除查询。

条目以更正的形式排序。删除第一个元素后,迭代器从底部开始,排序从 ZtoA 开始,而不是从 AtoZ 开始。

是否可以保留排序?

结果应该是:[a, b, c, d, e, f]

0 投票
3 回答
3250 浏览

c++ - using remove_if for a map container

I was trying to use remove_if template for a map container but I am getting compiler error for the template argument. I am unable to understand why.

This remove_if is throwing compiler errors. Any suggestion to fix it?

Error message is

0 投票
1 回答
87 浏览

loops - Removing separate list of items from another list in Python 3.x

I have a list that contains a lot of tagged bigrams. Some of the bigrams are not tagged correctly so I want to remove them from the master list. One of the words of a bigrams keeps repeating frequently, so I can remove the bigram if it contains an xyz word. Psudo example is below:

I can remove the items separately, i.e. every time I create a list and remove the items which contain the word, say, 'on'. This is tedious and it will require hours of filtering and creating new lists for filtering each unwanted word. I thought that a loop will help. However, I get the following type error:

Your help is highly appreciated!

0 投票
1 回答
618 浏览

predicate - 使用谓词 C++11 从 unordered_map 中擦除的非循环有效方法?

在使用容器时,为了提高效率,建议使用算法和成员函数。但是,关联容器(unordered_map)不适用于擦除(remove_if)范式,似乎常用的方法是退回到循环上。

uom 是一个 std::unordered_map

//根据 Scott Meyers 有效 STL pg45

这是否尽可能高效?似乎应该有一个更好的方法来使用像擦除(remove_if)范例这样的东西来做到这一点,但它适用于unordered_map(我知道关联容器不能“重新排序”,因此不支持remove_if算法) . 这真的是使用谓词从 unordered_map 中删除条目的最佳方法吗?有什么建议么?

先感谢您。