atom-sorter
Advanced tools
Comparing version 0.8.0 to 0.9.1
{ | ||
"name": "atom-sorter", | ||
"version": "0.8.0", | ||
"version": "0.9.1", | ||
"description": "Callback allowing to sort chemical elements (atoms) in Hill order", | ||
@@ -21,4 +21,4 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"mf-utilities": "^0.8.0" | ||
"mf-utilities": "^0.9.1" | ||
} | ||
} |
@@ -6,7 +6,7 @@ 'use strict'; | ||
test('atom-sorter test', () => { | ||
expect(atomSorter('C', 'C')).toBe(0); | ||
expect(atomSorter('C', 'H')).toBe(-1); | ||
expect(atomSorter('C', 'O')).toBe(-1); | ||
expect(atomSorter('N', 'O')).toBe(-1); | ||
expect(atomSorter('Cl', 'Br')).toBe(1); | ||
expect(atomSorter('C', 'C')).toBe(0); | ||
expect(atomSorter('C', 'H')).toBe(-1); | ||
expect(atomSorter('C', 'O')).toBe(-1); | ||
expect(atomSorter('N', 'O')).toBe(-1); | ||
expect(atomSorter('Cl', 'Br')).toBe(1); | ||
}); | ||
@@ -16,11 +16,11 @@ | ||
test('sort an array', () => { | ||
let atoms = ['H', 'Cl', 'C', 'O', 'N', 'Br']; | ||
atoms.sort((a, b) => atomSorter(a, b)); | ||
expect(atoms).toEqual(['C', 'H', 'Br', 'Cl', 'N', 'O']); | ||
let atoms = ['H', 'Cl', 'C', 'O', 'N', 'Br']; | ||
atoms.sort((a, b) => atomSorter(a, b)); | ||
expect(atoms).toStrictEqual(['C', 'H', 'Br', 'Cl', 'N', 'O']); | ||
}); | ||
test('sort an array HCl', () => { | ||
let atoms = ['Cl', 'H']; | ||
atoms.sort((a, b) => atomSorter(a, b)); | ||
expect(atoms).toEqual(['H', 'Cl']); | ||
let atoms = ['Cl', 'H']; | ||
atoms.sort((a, b) => atomSorter(a, b)); | ||
expect(atoms).toStrictEqual(['H', 'Cl']); | ||
}); |
'use strict'; | ||
function atomSorter(a, b) { | ||
if (a === b) return 0; | ||
if (a === 'C') return -1; | ||
if (b === 'C') return 1; | ||
if (a === 'H') return -1; | ||
if (b === 'H') return 1; | ||
if (a < b) return -1; | ||
return 1; | ||
if (a === b) return 0; | ||
if (a === 'C') return -1; | ||
if (b === 'C') return 1; | ||
if (a === 'H') return -1; | ||
if (b === 'H') return 1; | ||
if (a < b) return -1; | ||
return 1; | ||
} | ||
module.exports = atomSorter; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3112
+ Addedchemical-elements@0.9.1(transitive)
+ Addedchemical-groups@0.9.1(transitive)
+ Addedmf-parser@0.9.1(transitive)
+ Addedmf-utilities@0.9.1(transitive)
- Removedchemical-elements@0.7.0(transitive)
- Removedchemical-groups@0.8.0(transitive)
- Removedmf-parser@0.8.0(transitive)
- Removedmf-utilities@0.8.0(transitive)
Updatedmf-utilities@^0.9.1