Files
30-seconds-of-code/snippets/expandTabs.md
Angelos Chalaris 60d2238718 Add expandTabs
2020-06-01 17:05:39 +03:00

410 B

title, tags
title tags
expandTabs string,regexp,beginner

Convert tabs to spaces, where each tab corresponds to count spaces.

Use String.prototype.replace() with a regular expression and String.prototype.repeat() to replace each tab character with count spaces.

const expandTabs = (str, count) => str.replace(/\t/g, ' '.repeat(count));
expandTabs('\t\tlorem', 3); // '      lorem'