2018-09-30 23:01:58 +01:00
---
title: SEDOLs
id: 59d9c6bc214c613ba73ff012
challengeType: 5
2020-05-21 17:31:25 +02:00
isHidden: false
2019-08-05 09:17:33 -07:00
forumTopicId: 302305
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
2019-07-18 17:32:12 +02:00
2019-03-07 23:15:29 +09:00
For each number list of 6-digit < a href = "https://en.wikipedia.org/wiki/SEDOL" title = "wp: SEDOL" target = "_blank" > SEDOL< / a > s, calculate and append the checksum digit.
That is, given the input string on the left, your function should return the corresponding string on the right:
< pre >
710889 => 7108899
B0YBKJ => B0YBKJ7
406566 => 4065663
B0YBLH => B0YBLH2
228276 => 2282765
B0YBKL => B0YBKL9
557910 => 5579107
B0YBKR => B0YBKR5
585284 => 5852842
B0YBKT => B0YBKT7
B00030 => B000300
< / pre >
Check that each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string. Your function should return < code > null< / code > on an invalid input.
2018-09-30 23:01:58 +01:00
< / section >
## Instructions
< section id = 'instructions' >
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
2019-11-20 07:01:31 -08:00
- text: < code > sedol</ code > should be a function.
2019-07-26 05:24:52 -07:00
testString: assert(typeof sedol === 'function');
2019-03-19 15:04:03 +05:30
- text: < code > sedol('a')</ code > should return null.
2019-07-24 05:06:12 -07:00
testString: assert(sedol('a') === null);
2019-03-19 15:04:03 +05:30
- text: < code > sedol('710889')</ code > should return '7108899'.
2019-07-24 05:06:12 -07:00
testString: assert(sedol('710889') === '7108899');
2019-03-19 15:04:03 +05:30
- text: < code > sedol('BOATER')</ code > should return null.
2019-07-24 05:06:12 -07:00
testString: assert(sedol('BOATER') === null);
2019-03-19 15:04:03 +05:30
- text: < code > sedol('228276')</ code > should return '2282765'.
2019-07-24 05:06:12 -07:00
testString: assert(sedol('228276') === '2282765');
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
2019-03-07 23:15:29 +09:00
function sedol(input) {
2018-09-30 23:01:58 +01:00
// Good luck!
return true;
}
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
function sedol(input) {
const checkDigit = sedolCheckDigit(input);
if (checkDigit !== null) {
return input + checkDigit;
}
return null;
}
const weight = [1, 3, 1, 7, 3, 9, 1];
function sedolCheckDigit(char6) {
if (char6.search(/^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}$/) === -1) {
return null;
}
let sum = 0;
for (let i = 0; i < char6.length ; i + + ) {
sum += weight[i] * parseInt(char6.charAt(i), 36);
}
const check = (10 - (sum % 10)) % 10;
return check.toString();
}
```
< / section >