Skip to content

zongzw/intensity-segment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Intensity Segments

Repository Description

This repository presents IntensitySegements problem and solution in golang and javascript.

Find the details in the separate folders. The golang edition is well auto unit-tested and commented.

Problem Description

We are looking for a program that manages “intensity” by segments.

Segments are intervals from -infinity to infinity, we’d like you to implement functions that updates intensity by an integer amount for a given range.

All intensity starts with 0. Please implement these three functions:

/** *
 * NOTE: Feel free to add any extra member variables/functions you like.
 */
export class IntensitySegments {
    /**
     *
     */
    add(from, to, amount) {
        // TODO: implement this
    }
    /** 
     *
     */
    set(from, to, amount) {
        // TODO: implement this
    }
    /** 
     *
     */
    toString() {
        // TODO: implement this
    }
}


// Here is an example sequence:
// (data stored as an array of start point and value for each segment.) 

const segments = new IntensitySegments();
segments.toString(); // Should be "[]"
segments.add(10, 30, 1);
segments.toString(); // Should be: "[[10,1],[30,0]]"
segments.add(20, 40, 1);
segments.toString(); // Should be: "[[10,1],[20,2],[30,1],[40,0]]"
segments.add(10, 40, -2);
segments.toString(); // Should be: "[[10,-1],[20,0],[30,-1],[40,0]]"

// Another example sequence:
const segments = new IntensitySegments(); 
segments.toString(); // Should be "[]"
segments.add(10, 30, 1);
segments.toString(); // Should be "[[10,1],[30,0]]"
segments.add(20, 40, 1);
segments.toString(); // Should be "[[10,1],[20,2],[30,1],[40,0]]"
segments.add(10, 40, -1);
segments.toString(); // Should be "[[20,1],[30,0]]"
segments.add(10, 40, -1);
segments.toString(); // Should be "[[10,-1],[20,0],[30,-1],[40,0]]"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published