* Trims leading and trailing whitespace, such as spaces and tabs, * from String table values. If no column is specified, then the * values in all columns and rows are trimmed. A specific column * may be referenced by either its ID or title. * * @deprecated p5.Table will be removed in
(column)
| 767 | * // 1 "Snake" "Reptile" |
| 768 | */ |
| 769 | trim (column) { |
| 770 | const regex = new RegExp(' ', 'g'); |
| 771 | |
| 772 | if (typeof column === 'undefined') { |
| 773 | for (let c = 0; c < this.columns.length; c++) { |
| 774 | for (let d = 0; d < this.rows.length; d++) { |
| 775 | let s = this.rows[d].arr[c]; |
| 776 | s = s.replace(regex, ''); |
| 777 | this.rows[d].arr[c] = s; |
| 778 | this.rows[d].obj[this.columns[c]] = s; |
| 779 | } |
| 780 | } |
| 781 | } else if (typeof column === 'string') { |
| 782 | for (let j = 0; j < this.rows.length; j++) { |
| 783 | let val = this.rows[j].obj[column]; |
| 784 | val = val.replace(regex, ''); |
| 785 | this.rows[j].obj[column] = val; |
| 786 | const pos = this.columns.indexOf(column); |
| 787 | this.rows[j].arr[pos] = val; |
| 788 | } |
| 789 | } else { |
| 790 | for (let k = 0; k < this.rows.length; k++) { |
| 791 | let str = this.rows[k].arr[column]; |
| 792 | str = str.replace(regex, ''); |
| 793 | this.rows[k].arr[column] = str; |
| 794 | this.rows[k].obj[this.columns[column]] = str; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * Use <a href="/reference/p5.Table/removeColumn/">removeColumn()</a> to remove an existing column from a Table |
no outgoing calls
no test coverage detected