Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b8ec257

Browse files
Create findLengthMap.js
1 parent 712128f commit b8ec257

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎Javascript/findLengthMap.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Given an array of strings, use the JavaScript map() function to return an array containing length of string at each index. The input array can be of length 0
2+
//Return 0 if the string is null or undefined
3+
4+
function findLength(arr) {
5+
arr = arr.map((str) => {
6+
if(str === null || str === undefined) return 0
7+
else return str.length
8+
})
9+
return arr;
10+
}
11+
12+
module.exports = findLength;
13+
const arr = [null]
14+
console.log(findLength(arr))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /