Question

Given a string, return true if the number of appearances of "is" anywhere in the string...

Given a string, return true if the number of appearances of "is" anywhere in the string is equal to the number of appearances of "not" anywhere in the string (case sensitive). Complete function isNot (including the function heading) to accomplish this. The following assertions must pass.

console.assert( isNot("isisnotnot") )
console.assert( isNot("isnot") )
console.assert( isNot("_not_is_not_is_") )
console.assert( isNot( "abc" ) ) // zero is's, zero nots
console.assert( isNot("_is_is_not_") === false )

Homework Answers

Answer #1

function isNot(str){
var numIs=0;
var numNot=0;
var ind=str.indexOf("is",0);
while(ind!=-1){
numIs+=1;
ind = str.indexOf("is",ind+2);
}
ind=str.indexOf("not",0);
while(ind!=-1){
numNot+=1;
ind = str.indexOf("not",ind+3);
}
return (numNot==numIs);
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True...
#Write a function called has_a_vowel. has_a_vowel should have #one parameter, a string. It should return True if the string #has any vowels in it, False if it does not. def has_a_vowel(a_str): print("Starting...") for letter in a_str: print("Checking", letter) if letter in "aeiou": print(letter, "is a vowel, returning True") return True else: print(letter, "is not a vowel, returning False") return False print("Done!")       #Below are some lines of code that will test your function. #You can change the value of...
Number of years to provide a given return   In the information given in following​ case, determine...
Number of years to provide a given return   In the information given in following​ case, determine the number of years that the given ordinary annuity cash flows must continue in order to provide the rate of return on the initial amount. Initial amount Annual cash flow    Rate of return ​$33,200 ​$10,321 16​% The number of investment​ years, n​, is years????  ​(Round to two decimal​ places.) Number of years to equal future amount   For the following​ case, determine the number...
Write a recursive function block_count(string) to return the number of blocks consisting of the same letter...
Write a recursive function block_count(string) to return the number of blocks consisting of the same letter in the given input string. Example. >>> block_count ('AABBCCBBDDD') 5 >>>block_count ('GGABAA') 4
IN JAVA: Write recursive method to return true if a given array has element equal to...
IN JAVA: Write recursive method to return true if a given array has element equal to employee emp, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary, // and it has method boolean equals(Employee emp) that accept an employee object and returns true if employee calling the equals method is equal as employee emp,...
The following statements are, given certain assumptions, either true, false, or partly true and partly false....
The following statements are, given certain assumptions, either true, false, or partly true and partly false. State which is the case and give your reasons. It is the accuracy of your reasons that principally determines your grade. 5. (10 points) Whenever the rate of profit on capital is positive, the rate of exploitation of labor must be positive and equal to the rate of profit.
php please numberOfPairs // Return the number of times a pair occurs in array. A pair...
php please numberOfPairs // Return the number of times a pair occurs in array. A pair is any two String values that are equal (case // sensitive) in consecutive array elements. The array may be empty or have only one element. In both of // these cases, return 0. // // numberOfPairs( array('a', 'b', 'c') ) returns 0 // numberOfPairs( array('a', 'a', 'a') ) returns 2 // assert(2 == numberOfPairs( array('a', 'a', 'b', 'b' ) ) ); // numberOfPairs( array...
Write recursive method to return true if a given array of integers, named numbers, with n...
Write recursive method to return true if a given array of integers, named numbers, with n occupied positions is sorted in ascending (increasing) order, or returns false otherwise. Array can be empty or not. //PRECONDITION: Varible n denotes the number of occupied positions in the array and must be non-negative. Employee class has method getSalary() that returns employee's salary. // An empty array and an array with single element in it, are sorted. Method isSortedRec must be recursive and returns...
Write a recursive method to return all possible k permutations of the given String non-zeros number...
Write a recursive method to return all possible k permutations of the given String non-zeros number Sample input : "123" , 2 output : "1-2", "1-3", "2-3", "2-1", "3-1", "3-2" ** Please provide -PSEUDO CODE -UML DIAGRAM
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a...
Write a function int count_consonants(char str[]) that determines and returns the number of consonants in a given string. Then write a simple main() function where you can repeatedly enter a string and then the num- ber of consonants is determined and printed on the screen (from the main() function). If the entered string is empty (it will contain only a ’\n’ then) the program should stop its execution. You can safely assume that the entered string will be not longer...
(In Python) Complete the isPrime() function to take an int and return True if it is...
(In Python) Complete the isPrime() function to take an int and return True if it is a prime number and False if it is not. Note: A prime number is not evenly divisible (meaning, the remainder is not 0) for all numbers smaller than itself (down to 2). For example, if num is 7, then you could test: if 7 remainder 6 is not 0, then if 7 remainder 5 is not 0, then if 7 remainder 4 is not...