Angram

in #ita15 days ago

export class Anagram {
input : string;
constructor(input: string) {
this.input = input.toLowerCase();
}

public matches(...potentials: string[]): string[] {
let res: string[] = [];
let sortedStringFirst: string = this.input.split('').sort().join('');
for(let potential of potentials){
let toLow = potential.toLowerCase();
let sortedString: string = toLow.split('').sort().join('');
if(this.input != toLow && sortedString == sortedStringFirst && this.input.length == potential.length)
res.push(potential);
}
return res;
}
}