<<<<<<< HEAD Code Wars - Brett Crafton

Return Negative

Question

In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative? Notes The number can be negative already, in which case no change is required. Zero (0) is not checked for any specific sign. Negative zeros make no mathematical sense. Examples

makeNegative(1); // return -1 makeNegative(-5); // return -5 makeNegative(0); // return 0 makeNegative(0.12); // return -0.12

Solution by -

My Solution


	function makeNegative(num) {
		return Math.sign(num) == 1 ? - num : num
		}
				

Try it yourself - CodeWars

======= Code Wars - Brett Crafton

Return Negative

Question

In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative? Notes The number can be negative already, in which case no change is required. Zero (0) is not checked for any specific sign. Negative zeros make no mathematical sense. Examples

makeNegative(1); // return -1 makeNegative(-5); // return -5 makeNegative(0); // return 0 makeNegative(0.12); // return -0.12

Solution by -

My Solution


	function makeNegative(num) {
		return Math.sign(num) == 1 ? - num : num
		}
				

Try it yourself - CodeWars

>>>>>>> 0e614172debaa009c8d31330edbeb3b765b59c39