Skip to content

Commit 841839f

Browse files
authored
Create 1271-hexspeak.js
1 parent 03867ff commit 841839f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1271-hexspeak.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {string} num
3+
* @return {string}
4+
*/
5+
var toHexspeak = function(num) {
6+
const hex = ((+num)).toString(16).toUpperCase()
7+
let res = ''
8+
for(let ch of hex) {
9+
if(ch > '1' && ch <= '9') return 'ERROR'
10+
else if(ch === '0') res += 'O'
11+
else if(ch === '1') res += 'I'
12+
else res += ch
13+
}
14+
return res
15+
};

0 commit comments

Comments
 (0)