6 kyu
Hex class
25 of 1,572josher19
Description:
Create a class Hex which takes a number as an argument.
Adding a hex object to a number (by using valueOf
) generates a number, but calling toString
or toJSON
will show its hexadecimal value starting with "0x". To make hex objects comparable you have to provide a method equals
.
Example:
FF = new Hex(255)
FF.toString() == "0xFF"
FF.valueOf() + 1 == 256
Also create two methods, plus
and minus
which will add or subtract a number or Hex object and return a new Hex object.
a = new Hex(10)
b = new Hex(5)
a.plus(b).toJSON() == "0xF"
Also, create a parse
class method that can parse Hexadecimal numbers and convert them to standard decimal numbers:
Hex.parse("0xFF") == 255
Hex.parse("FF") == 255
Note: If you define both valueOf
and toString
, "Hex value:" + new Hex(255) may not behave as expected!
Algorithms
Parsing
Fundamentals
Object-oriented Programming
Similar Kata:
Stats:
Created | Dec 6, 2014 |
Published | Dec 6, 2014 |
Warriors Trained | 3030 |
Total Skips | 357 |
Total Code Submissions | 9957 |
Total Times Completed | 1572 |
CoffeeScript Completions | 25 |
JavaScript Completions | 1296 |
Java Completions | 267 |
Total Stars | 56 |
% of votes with a positive feedback rating | 91% of 175 |
Total "Very Satisfied" Votes | 146 |
Total "Somewhat Satisfied" Votes | 26 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 24 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 7 kyu |