我刚接触React和create-react-app,我试图在我的App.js文件中使用Lodash,但我遇到了错误。Uncaught TypeError: _this.reduce is not a function。我已经添加了
import _ from 'lodash';
import shuffle from 'lodash/shuffle';
import random from 'lodash/random';
import find from 'lodash/find';
添加到我的App.js的顶部
import
在一个专注于健康实践的应用程序中,我需要检查一个数组是否存在于另一个数组中。匹配条件是:*是否有额外的非匹配元素并不重要*如果一个术语出现在“海草堆”数组中不止一次并不重要
我们在Lodash的讨论中找到了一个很好的解决方案。它是在JSFiddle中模拟出来的,似乎运行得很好。
但在这个相当复杂的应用程序中,它使用Lodash将浏览器炸开。
各种配置
这是用于Lodash的代码。
let haystack = ['health tips','iridology','something else','asdfasd'];
let n
例如:
input: var arr = ['a','b','c','a-5','c-2'];
output: var result = {'a':6,'b':1,'c':'3'} ;
我的解决方案是:
function countSameItem(arr) {
var counter = {};
for (var i = 0; i < arr.length; i++) {
var item = arr[i].split('-'
使用LoDash对对象进行映射:
_.map(items, (item) = > {
if (Array.isArray(item)) {
// don't include this in final object
}
return _.assign({
foo: "bar"
}, item);
});
想知道如果当前对象是数组的话,我最好的策略是在返回的、映射的对象中不包含一个对象?