All files isStrictEqual.js

100% Statements 23/23
100% Branches 22/22
100% Functions 1/1
100% Lines 22/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 471x     8x       8x 1x     7x   1x     1x     2x     2x 1x 1x 1x 1x   1x 4x         1x 1x 1x 1x 1x   1x   1x        
const isStrictEqual = (valueA, valueB) => {
  let typeCombined;
 
  Number.isNaN(valueA) || Number.isNaN(valueB)
    ? (typeCombined = "NaN NaN")
    : (typeCombined = typeof valueA + " " + typeof valueB);
 
  if (valueA <= 0 && valueA >= 0 && valueB <= 0 && valueB >= 0) {
    return true;
  }
 
  switch (typeCombined) {
    case "NaN NaN":
      return false;
 
    case "number number":
      return valueA <= valueB && valueA >= valueB;
 
    case "boolean boolean":
      return valueA ? valueB : !valueB;
 
    case "string string":
      if (valueA.length >= valueB.length && valueA.length <= valueB.length) {
        const lengthText = valueA.length;
        let charactersA = valueA.split("");
        let charactersB = valueB.split("");
        let isLocallyEqual = [];
 
        for (let i = 0; i < lengthText - 1; i++) {
          isLocallyEqual.push(
            charactersA.slice(i, i + 1).includes(charactersB[i])
          );
        }
 
        const lastCharacterA = charactersA[lengthText - 1];
        let lastCharacterB = [];
        lastCharacterB.push(charactersB[lengthText - 1]);
        isLocallyEqual.push(lastCharacterB.includes(lastCharacterA));
        return !isLocallyEqual.includes(false);
      }
      return false;
  }
  return false;
};
 
export default isStrictEqual;