sylarific
BAN USER- 0of 0 votes
AnswersFunction that will accept a string as the only parameter and returns a string that contains the number of characters in each word (including punctuations) of that string. separated by spaces
- sylarific in United States
Eg. Input : "career cup."
Output: "6 4"
eg. Input: "Dark. Knight, Rises!"
Output : "5 7 6"| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm - 0of 0 votes
AnswerHow would you build a stock ticker service?
- sylarific in United States for Web Developer| Report Duplicate | Flag | PURGE
Front-end Software Engineer Coding - 0of 0 votes
AnswersAssuming a preexisting list of 100 words, how would you efficiently see if a word received from input is an anagram of any of the 100 words?
- sylarific in United States for Web Developer| Report Duplicate | Flag | PURGE
Front-end Software Engineer Algorithm - 0of 0 votes
AnswersWhat are some ways of improving performance of the web pages using HTML, JS and CSS optimization?
- sylarific in United States for Web Developer| Report Duplicate | Flag | PURGE
Front-end Software Engineer Application / UI Design - 0of 0 votes
AnswersGiven an array, print combinations of the array elements such that it is printed only once and the order is not important between the elements. Eg. array = [a,b,c,d]
- sylarific in United States
o/p should be "", a,b,c,d,ab,ac,ad,bc,bd,cd,abc,abd,acd,bcd, abcd.. so it should not repeat abc in the form cab or bca etc..
Output number wil always be 2^n and do this in O(1) space.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm
just to modify a bit on your code, since we need to return a string, may be this works:
- sylarific July 22, 2012<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to convert the array into a String.</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
//var s = "career cup.";
var s= "Dark, Knight, Rises!";
var ans=[];
var count = 1;
for(i=0; i<s.length; i++)
{
if(s[i] == " ")
{
// document.write((count-1)+"<br/>");
ans.push(count-1);
count = 0;
}
else if( i == s.length-1 )
{ ans.push(count);
}
// document.write(count);
count++;
}
ans.toString();
//document.write(ans);
var x=document.getElementById("demo");
x.innerHTML=ans;
}
</script>
</body>
</html>