Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

reverse a string if its value its greater than 3

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'
Comment

PREVIOUS NEXT
Code Example
Typescript :: running same test in different environment 
Typescript :: typescript nested array 
Typescript :: typescript type plus one property 
Typescript :: accessing python dictionary values with dot 
Typescript :: how to display dotted line betweens 2 series point in high charts react native 
Typescript :: how to check if a field exists in a dictionry or not 
Typescript :: which of the following are elements associated with the html table layout? 
Typescript :: Fechas - Solución resta un día en dato 
Typescript :: optional or required depending on param is true react typescript 
Typescript :: mongoose get all documents big 
Typescript :: Q5: Identify the five major components of a communications system. 
Typescript :: type script 
Typescript :: calculate checksum typescript 
Typescript :: ionic ios REST API CORS issue 
Typescript :: typescript map interface 
Typescript :: function in c that converts current time in timezone 
Typescript :: python unix get 5 minuts from now 
Typescript :: ips in range typescript 
Typescript :: tkinter widgets overview 
Typescript :: java objects cannot change? 
Typescript :: TypeError: agent_go() takes 0 positional arguments but 1 was given 
Typescript :: yup validation typescript 
Typescript :: typescript set 
Typescript :: mac mini late 2010 
Typescript :: tiqets endpoints 
Cpp :: find largest number in vector c++ 
Cpp :: qstring mid 
Cpp :: fahrenheit to kelvin formula 
Cpp :: c++ messagebox 
Cpp :: map key exists c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =