React
- 0 ответов
- 2 вопроса
2
Вклад в тег
const parseArrayOfLines = (arrayOfLines) => {
const result = {};
try {
arrayOfLines.forEach((line) => {
const lineTokens = line.split(' ');
const equalsPosition = lineTokens.indexOf('=');
const isValidLine = equalsPosition !== -1;
if (!isValidLine) {
return;
}
const keyPosition = equalsPosition - 1;
const valuePosition = equalsPosition + 1;
result[lineTokens[keyPosition]] = lineTokens[valuePosition];
});
} catch (error) {
//
} finally {
return result;
}
};