How to check if all strings are lexically equal in array of strings with TypeScript

1 Answer

0 votes
function strings_are_equal(arr: string[]) {
    let result: boolean = true, i: number = 0;
    
    while (++i < arr.length) {
        result = result && (arr[i - 1] === arr[i]);
    } 
    return result;
}

const arr: string[] = ['ts', 'ts', 'ts', 'ts'];

console.log(strings_are_equal(arr)); 




/*
run:

true

*/

 



answered Aug 13, 2023 by avibootz
...