+ 2

Remove word and insert sentence in the words array

challenge is to replace words with matching sentence. Sentence will include words in order. ex: let wordsArray = ["hello", "javascript", "is","cool","&","sololearn","is","cool","hello","sololearn"]; let sentence = "is cool" //logic for updated array output: wordsArray = ["hello", "javascript", "is cool","&","sololearn","is cool","hello","sololearn]

17th Nov 2017, 6:35 PM
Vinod Chandaliya
Vinod Chandaliya - avatar
4 Réponses
+ 5
homework?
15th Nov 2017, 9:37 AM
qwerty
qwerty - avatar
+ 3
Try to iterate through your array, then on each iteration, verify, if (array[i] + " " + array[i+1] == sentence), add sentence to output array, then skip array[i+1], else add the array[i] to the output array as usual. Hope it works :)
16th Nov 2017, 9:17 AM
Ipang
+ 1
Bit tricky
16th Nov 2017, 6:55 AM
Vinod Chandaliya
Vinod Chandaliya - avatar
+ 1
@lpang I have tried it in this way, but I think this solution is not complete- https://code.sololearn.com/W0NUXlJPBP3k
17th Nov 2017, 6:57 PM
Vinod Chandaliya
Vinod Chandaliya - avatar