-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiply-word-in-string.js
More file actions
30 lines (22 loc) · 1002 Bytes
/
multiply-word-in-string.js
File metadata and controls
30 lines (22 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
You are to write a function that takes a string as its first parameter. This string will be a string of words.
You are expected to then use the second parameter, which will be an integer, to find the corresponding word in the given string. The first word would be represented by 0.
Once you have the located string you are finally going to multiply by it the third provided parameter, which will also be an integer. You are additionally required to add a hyphen in between each word.
Example
modifyMultiply ("This is a string",3,5)
Should return
"string-string-string-string-string"
Since the 3rd word is 'string'(starting from 0 remember) and the third paramater indicates that it should be repeated 5 times.
Simple. Good luck.
*/
function modifyMultiply (str,loc,num) {
let stringReturn = ''
for (let i = 0; i < num; i++){
if (i == num - 1){
stringReturn += str.split(' ')[loc]
} else {
stringReturn += str.split(' ')[loc] + '-'
}
}
return stringReturn
}