A road of infinite length has been painted many times.
[2,4]
means it has been painted from 2 meters to 4 meters
[5.5,6.75]
means it has been painted from 5.5 meters to 6.75 and so on.
Given a list of painted pairs, figure out how much of the road has been painted.
[[2,4],[5.5,6.75]] => 3.25
[[2,4],[3,5]] => 3 (the part [3,4] has been painted twice and should not be considered twice)
function getTotalPaintedLength(paints) {
//Write your code here
return 0;
}
expect(getTotalPaintedLength([[2,4],[5.5,6.75]])).toBe(3.25)
expect(getTotalPaintedLength([[2,4],[3,5]])).toBe(3)
expect(getTotalPaintedLength([[2,4],[5.5,6.75]])).toBe(3.25);
expect(getTotalPaintedLength([[2,4],[3,5]])).toBe(3);
expect(getTotalPaintedLength([[2,4],[3,5],[4,7]])).toBe(5);
expect(getTotalPaintedLength([[2,4],[3,5],[6.75,8]])).toBe(4.25);
expect(getTotalPaintedLength([[7,10],[15,20],[24,27]])).toBe(11);
expect(getTotalPaintedLength([[4, 7], [1, 5], [3, 10]])).toBe(9);
expect(getTotalPaintedLength([[4,15],[7,12],[15,18],[28,36]])).toBe(22);
expect(getTotalPaintedLength([[3,7],[7,12],[9,18],[100,104]])).toBe(19);
expect(getTotalPaintedLength([[8,9],[17,19],[23,37],[28,36]])).toBe(17);
expect(getTotalPaintedLength([[0,2],[1,3],[2,4]])).toBe(4);
expect(getTotalPaintedLength([[0,3],[0,2],[1,2.5]])).toBe(3);
export function number_cardinality( my_number ) {
if (my_number % 10 === 0) {
return "zero";
}
else if (my_number % 10 === 5) {
return "five";
}
else if (my_number % 2 === 0) {
return "even";
}
else {
return "odd";
}
}
console.log(number_cardinality(100)); // "zero"
console.log(number_cardinality(88)); // "even"
console.log(number_cardinality(155)); // "five"
console.log(number_cardinality(99)); // "odd"