Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

string split into three non empty combination js

const string = "abcd";

const array = string.split("");

const output = array.reduce((carry, _, idx, arr) => {
    if (idx < arr.length - 1) {
        const str = arr[idx] + arr[idx + 1];
        const subArray = [...arr];
        subArray.splice(idx, 2, str);
        carry.push(subArray);
    }
    return carry;
}, []);

console.log(output);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: node-mongodb-native keep collection 
Javascript :: Pass 3 of the same thing to ExpressJS with a form 
Javascript :: Using javascript code in Jade views - if(variable) shows undefined instead of passing 
Javascript :: nodejs api find data with id 
Javascript :: mongodb create index json 
Javascript :: regex online converter 
Javascript :: FlatList load top 
Javascript :: react native push notifications cancel delivered notification 
Javascript :: Declare JSON Variable In Another File 
Javascript :: convert pcap fiole to json tshark 
Javascript :: Uncaught (in promise) TypeError: dispatch is not a function 
Javascript :: phaser max size of group or pool 
Javascript :: switching light bulbs problem javascript 
Javascript :: add attribute to element in jquery 
Javascript :: force browser reload page from server javascript 
Javascript :: change button text dynamically angular 6 
Javascript :: routing/switches 
Javascript :: cookie in Auth header 
Javascript :: react-native navigation homeStack 
Javascript :: how to skip the else statment in react tertiary 
Javascript :: javascript remove the second to last character of a string 
Javascript :: problem with Next.js and @material-ui. 
Javascript :: wait untill 2 
Javascript :: strictPopulate 
Javascript :: site:stackoverflow.com how to see all react dependencies 
Javascript :: nested object in javascript 
Javascript :: Closure examples 
Javascript :: higher order function javascript 
Javascript :: comment field react 
Javascript :: moment js remove seconds 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =