paeseInt vs Implicit return the same result but second failing in jest

Viewed 32

what is the difference between these two codes? they result in the same but the jest not passing for implicit return

// version one:

function reverseInt(n) {
  const reverseInt = n.toString().split("").reverse().join("");
  return parseInt(reverseInt) * Math.sign(n);
}

//version two 

function reverseInt(n) {
  const reverseInt = n.toString().split("").reverse().join("");
  return reverseInt * Math.sign(n);
} 

the jest are below, let me know if need anything to discover more about this issue. i want to know the reason why thanks for your time!!

const reverseInt = require('./index');

test('ReverseInt function exists', () => {
  expect(reverseInt).toBeDefined();
});

test('ReverseInt handles 0 as an input', () => {
  expect(reverseInt(0)).toEqual(0);
});

test('ReverseInt flips a positive number', () => {
  expect(reverseInt(5)).toEqual(5);
  expect(reverseInt(15)).toEqual(51);
  expect(reverseInt(90)).toEqual(9);
  expect(reverseInt(2359)).toEqual(9532);
});

test('ReverseInt flips a negative number', () => {
  expect(reverseInt(-5)).toEqual(-5);
  expect(reverseInt(-15)).toEqual(-51);
  expect(reverseInt(-90)).toEqual(-9);
  expect(reverseInt(-2359)).toEqual(-9532);
});


0 Answers
Related