Split a string into two parts

Split a string into two parts
0

#1

For one of the basic algorithm challenges I would like to split a string into two parts using slice. I don’t want to use anything else, I’m determined to do it my probably very complex way!

So if I say

let str = ‘abcdef’;
let newStr = str.slice(1, str.length);
console.log (newStr)

I get ‘bcdef’, but my brain is fried and I can’t work out for my life how to get ‘a’ using slice.

Pls help!


#2

It will be str.slice(0, 1); :slight_smile:


#3

When I tried that in my console I got b! I started trying to do -1 and started thinking it must be impossible.

I now realise I must have tried the slice(0,1) with the ‘bcdef’ string that had been returned. Doh.

Thanks!