Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const prepareArray = (items: Array<number>, medianValue: number, direction: number) => {
- const data = items.map((x) => x * direction > medianValue * direction ? x : null);
- const indexes = data.reduce((indexes: Array<number>, item, index) => {
- if (item) {
- if (data[index - 1] === null) indexes.push(index - 1);
- if (data[index + 1] === null) indexes.push(index);
- }
- return indexes;
- }, []);
- let indexOffset = 1;
- indexes.forEach(index => {
- data.splice(index + indexOffset, 0, medianValue);
- indexOffset++;
- });
- console.log(indexes);
- return data;
- };
- let testFunction = (items: Array<number>, medianValue: number) => {
- const hight = prepareArray(items, medianValue, 1);
- const low = prepareArray(items, medianValue, -1);
- return { hight, low };
- };
- let data = testFunction([10, 40, 60, 70, 80, 90, 10, 10, 70, 80, 90], 50);
- console.log(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement