reverse a string if its value its greater than 3

The solution for “reverse a string if its value its greater than 3” can be found here. The following code will assist you in solving the problem.

var s = ‘This is a short sentence’ // set test sentence
, e = s.split(‘ ‘) // ‘This is a short sentence’ ==> [‘This’,’is’,’a’,’short’,’sentence’]
.map(function(v,i,a){ // REPLACE the value of the current index in the array (run for each element in the array)
return v.length > 4 // IF the length of the a ‘word’ in the array is greater than 4
? v.split(”) // THEN return: ‘word’ ==> [‘w’,’o’,’r’,’d’]
.reverse() // [‘w’,’o’,’r’,’d’] ==> [‘d’,’r’,’o’,’w’]
.join(”) // [‘d’,’r’,’o’,’w’] ==> ‘drow’
: v; // OR return: the original ‘word’
}).join(‘ ‘); // [‘This’,’is’,’a’,’trohs’,’ecnetnes’] ==> ‘This is a trohs ecnetnes’

console.log(e); // ‘This is a trohs ecnetnes’

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

inline scripts encapsulated in