Skip to content

Commit

Permalink
Made search by gas name case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Mar 6, 2024
1 parent 4c75b65 commit d5a50c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions projects/scuba-physics/src/lib/Gases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ describe('Gases', () => {
});

describe('By name', () => {
it('IS case sensitive', () => {
it('IS NOT case sensitive', () => {
const found = StandardGases.byName('OXYGEN');
expect(found).toBeNull();
expect(found).not.toBeNull();
});

it('Oxygen', () => {
Expand Down
13 changes: 9 additions & 4 deletions projects/scuba-physics/src/lib/StandardGases.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Precision } from './precision';
import { Gas } from './Gases';
import _ from 'lodash';

export class StandardGases {
/** Relative partial pressure of oxygen in air at surface */
Expand Down Expand Up @@ -123,11 +124,15 @@ export class StandardGases {
return `${prefix} ${percentO2.toString()}/${percentHe.toString()}`;
}

// TODO consider to make it case insensitive
/** Case sensitive search. If nothing found returns null */
/** Case insensitive search. If nothing found returns null */
public static byName(name: string): Gas | null {
if (StandardGases.map.has(name)) {
const found = StandardGases.map.get(name);
const keys = [...StandardGases.map.keys()];
const foundKey = _(keys)
.filter((k) => k.toLowerCase() === name.toLowerCase())
.first();

if (foundKey) {
const found = StandardGases.map.get(foundKey);
return found ?? null;
}

Expand Down

0 comments on commit d5a50c3

Please sign in to comment.