score:1
your input to _.reduce
is just level1.test[teststate.id]
, which seems to be a non-array object. nothing in that code tells _.reduce
it would work on the .p1.o1
, .p1.o2
, and .p1.o3
properties on the object.
if you want to use reduce
for this, i'd use the native one and start with an array of property names:
checker2 = ['o1', 'o2', 'o3'].reduce(
(checker, prop) => checker && level1.test[teststate.id].p1 === undefined,
false
);
... in a optimized and less code
reduce
doesn't do either of those things. it requires creating an array and multiple function calls. instead:
const obj = level1.test[teststate.id].p1;
checker = obj.o1 === undefined && obj.o2 === undefined && obj.o3 === undefined;
(if you are going to use an array and callbacks, use every
as akx points out.)
score:4
it'd be easier (and more performant, as it has early-exit properties) to use array.every
:
const obj = level1.test[teststate.id].p1;
const checker1 = ['o1', 'o2', 'o3'].every(key => obj[key] === undefined);
Source: stackoverflow.com
Related Query
- .reduce in lodash fucntionality
- How to use plugin to reduce size when import lodash
- Next.js: Reduce data fetching and share data between pages
- lodash debounce in React functional component not working
- Lodash debounce with React Input
- React Native: Using lodash debounce
- Lodash debounce not working in React
- Lodash to find if object property exists in array
- Using Lodash debounce in React to prevent requesting data as long as the user is typing
- reduce JS execution time with NextJS
- Using lodash debounce to return a promise
- lodash isEmpty and has method vs simple check
- create-react-app reduce build size: main.[hash].chunk.js is 3MB+ with mostly images
- ReactJS + Material-UI: How to reduce column width of Material-UI's <TableRow/>?
- How to reduce renders using redux + normalizr
- How to analyze create react app build size and reduce it?
- How to reduce react context hell?
- How to reduce react app build time and understanding behaviour of webpack when bundling
- Why is all of lodash ending up in my webpack build?
- Better way to Get Property Than using Lodash
- lodash map get index key got unexpected token
- Does the use of es6 named imports reduce the bundle size when using webpack
- Lodash - how to pick only one item at a time from nested json?
- Does using React Hooks drastically reduce how code can be reused in React / Redux?
- How to reduce spacing between antd Form.Items?
- Lodash debounce async/await
- Getting lodash throttle to work with Redux Action
- Allow direct import of files within npm module like lodash
- How to reduce bundle size of first load page in Next.js?
- Sort mapped list with Lodash on ReactJS
More Query from same tag
- SVG viewbox error with React
- Reducer not being called in my Redux setup
- React State data not able to be passed as props
- React error boundary gets invoked but does not render
- How to validate email domains dynamically in Javascript
- How to get the name attribute in a bound function in react?
- ReactJS how to allow changes on an uncontrolled input?
- How to write localStorage in a Redux app using middleware?
- Is it bad form to call `createElement` manually?
- React: How to get data from Axios, not Promise?
- Detecting vertical page overflow using React
- how to use onClick on react-ripples?
- How can I add a custom color to a gradient with Tailwind and React?
- Trying to add a delete button to remove challenge from my list of challenges that I get my from my database
- Deploying ReactJs frontend + NodeJs backend to AWS
- Pass components as props to another component
- Filtering an api response in reactjs
- Deployed a website in React using Netlify, but I get a blank page
- "You need to enable JavaScript to run this app." error when deploying React/Express app to heroku
- What's the Difference between Remark & Rehype, and why would I want to use one over the other?
- React throws an error "Can't assign to property" scrollLeft "on 1: not an object" When trying use ref in custom function
- how to move focus to an item in react js?
- Set MUI Collapse component to "collapsed" by default
- CORS Error: LinkedIn Authentication; .NET Core 5 REST Api
- In a ReactJS app, how to substitute env vars from the global environment into my index.html file?
- redux fetch body is not use with no cors mode
- need to remove border from searchbar
- Method renders correctly when triggered one at a time, but not using _.map in React-Redux container
- React Router Redirect not Rendering
- How to change overflow style to hidden when modal opens