Skip to content

Instantly share code, notes, and snippets.

@evilsoft
Last active April 14, 2023 06:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilsoft/2d426f80c8768ea270572a2451a1e308 to your computer and use it in GitHub Desktop.
Save evilsoft/2d426f80c8768ea270572a2451a1e308 to your computer and use it in GitHub Desktop.
Simple Style Diffs
+ const isValidScore = score =>
+   score >= 70
+
+ const isValidUser = user =>
+   user && user.length > 3

data.reduce((acc, rec) => {
  const { score, user } = rec

- if(score <= 70) {
+ if(!isValidScore(score)) {
    return acc.concat([])
  }

- if(!(user && user.length > 3)) {
+ if(!isValidUser(user)) {
-   return acc.concat([])
+   return acc.concat([ 'unknown' ])
  }

  return acc.concat([ user ])
}, [])
const isValidScore = score =>
  score >= 70

const isValidUser = user =>
  user && user.length > 3

data.reduce((acc, rec) => {
  const { score, user } = rec
  
  if(!isValidScore(score)) {
    return acc.concat([])
  }
  
  if(!isValidUser(user)) {
-  return acc.concat([])
+  return acc.concat([ 'unknown' ])
  }

  return acc.concat([ user ])
}, [])
data.reduce((acc, {score, user}) => {
  const isScoreValid = score >=70;
  const isUserValid  = user && user.length > 3;
- return acc.concat([isScoreValid && isUserValid && user]);
+ if (isScoreValid add.push(isUserValid ? user : 'unknown');
+ return acc;
}, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment