-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathallSameLength.js
More file actions
19 lines (13 loc) · 710 Bytes
/
allSameLength.js
File metadata and controls
19 lines (13 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Coding in function ```cutIt```, function accept 1 parameter:```arr```. ```arr``` is a string array.
The first mission: Traversing ```arr```, find the shortest string length.
The second mission: Traversing ```arr``` again, intercept all strings to the shortest string length(Start from index0). you can use one of slice() substring() or substr() do it. return the result after finished the work.
for example:
```
cutIt(["ab","cde","fgh"]) should return ["ab","cd","fg"]
cutIt(["abc","defgh","ijklmn"]) should return ["abc","def","ijk"]
cutIt(["codewars","javascript","java"]) should return ["code","java","java"]
```
*/
//Answer//
let cutIt = a => a.map(x=>x.substr(0,Math.min(...a.map(x=>x.length))))