Series

in ita •  19 days ago 

export class Series {
series: string;
constructor(series: string) {
this.series = series;
if(this.series.length === 0) throw new Error('series cannot be empty');
}

slices(sliceLength: number): number[][] {
let res: number[][] = [];
if(sliceLength < 0) throw new Error('slice length cannot be negative');
if(sliceLength === 0) throw new Error('slice length cannot be zero');
if(this.series.length < sliceLength) throw new Error('slice length cannot be greater than series length');
for(let i=0; i<this.series.length-sliceLength+1; i++){
res.push(this.series.slice(i,i+sliceLength).split('').map(Number));
}
return res;
}
}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!