Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Last active January 27, 2020 13:30
Show Gist options
  • Save luojiyin1987/ee53cb893dd15bf5a9725e0134c46301 to your computer and use it in GitHub Desktop.
Save luojiyin1987/ee53cb893dd15bf5a9725e0134c46301 to your computer and use it in GitHub Desktop.
haveSameContents javascript
const haveSameContents = (a,b) => {
for(const v of new Set([...a, ...b]))
if (a.filter(e => e === v).length !== b.filter(e => e===v).length)
return false;
return true;
};
console.log(haveSameContents([1,2,4], [2,4,1]));
const isNumber = val => typeof val === 'number' && val === val;
console.log(isNumber(1));
console.log(isNumber('1'));
console.log(isNumber(NaN));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment