wip start
This commit is contained in:
parent
65ac71139e
commit
f5e4ad601a
@ -4,6 +4,7 @@ export const replaceWord = (str, toReplace, replacement) => {
|
|||||||
return str.slice(0, toReplace.start) + replacement + str.slice(toReplace.end)
|
return str.slice(0, toReplace.start) + replacement + str.slice(toReplace.end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This seems to work fine
|
||||||
export const wordAtPosition = (str, pos) => {
|
export const wordAtPosition = (str, pos) => {
|
||||||
const words = splitIntoWords(str)
|
const words = splitIntoWords(str)
|
||||||
const wordsWithPosition = addPositionToWords(words)
|
const wordsWithPosition = addPositionToWords(words)
|
||||||
@ -11,6 +12,7 @@ export const wordAtPosition = (str, pos) => {
|
|||||||
return find(wordsWithPosition, ({ start, end }) => start <= pos && end > pos)
|
return find(wordsWithPosition, ({ start, end }) => start <= pos && end > pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This works fine
|
||||||
export const addPositionToWords = (words) => {
|
export const addPositionToWords = (words) => {
|
||||||
return reduce(words, (result, word) => {
|
return reduce(words, (result, word) => {
|
||||||
const data = {
|
const data = {
|
||||||
@ -34,6 +36,7 @@ export const addPositionToWords = (words) => {
|
|||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This needs to be altered, split words at space
|
||||||
export const splitIntoWords = (str) => {
|
export const splitIntoWords = (str) => {
|
||||||
// Split at word boundaries
|
// Split at word boundaries
|
||||||
const regex = /\b/
|
const regex = /\b/
|
||||||
|
Loading…
Reference in New Issue
Block a user