I have a array of strings like the example below
["i.was.wen.the.coding", "i.am.wen.to", "i.am.new", "i.am", "i"]
u can see all sentence in array can be split by .
and I need to make logical algo pattern to create a sentence meaningful by taking the array in reverse and stitch back the words at the end. if u read it from last, as i.am.new.to.coding
taking last spit value from each sentence makes a meaningful sentence at last. am trying to create such a code in javascript or jquery and am stuck with this for more than a day. since it is so tricky.
any script experts plz help to make this. I appreciate your help. TIA
Seems straight forward, reverse the array, map it returning the last part after the period, then join with spaces
var arr = ["i.was.wen.the.coding", "i.am.wen.to", "i.am.new", "i.am", "i"];
var s = arr.reverse().map(function(x) {
return x.split('.').pop();
}).join(' ');
document.body.innerHTML = s;
var a = ["i.was.wen.the.coding", "i.am.wen.to", "i.am.new", "i.am", "i"];
var s = a.reduceRight(function(x,y){
return x + '.' + y.split('.').pop();
});
document.body.textContent = s;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With