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 f4efb60

Browse files
Create findLengthUsingMap.js
1 parent b8ec257 commit f4efb60

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎Javascript/findLengthUsingMap.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 によって変換されたページ (->オリジナル) /