Reputation: 17
getPath(array, 0) will return "A"
getPath(array, 1) will return "AB"
getPath(array, 2) will return "ABC"
function getPath(arr, idx){
// todo ...
}
var array = ["A","B","C"];
Upvotes: 0
Views: 137
Reputation: 411
Plain old for loop style:
function getPath(arr, idx){
var output="";
for(i=0;i<idx;i++){
output= output + array[i]
}
return output;
}
var array = ["A","B","C"];
Upvotes: 0
Reputation: 5544
function getPath(arr, idx){
return (arr.slice(0, idx+1).join(""));
}
Yes, you're right, thx Redu
Upvotes: 2