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,...
Write recursive method to return true if a given array has element equal to employee emp,...
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, and returns...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
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.
solve in python 3.8 please The question is about Strings Modify your function so that it...
solve in python 3.8 please The question is about Strings Modify your function so that it can handle the following two situations: The string given as an argument has no characters. In this case, you should return the empty string. The string given as an argument has one character. In this case, you should return the one-character string given to you. Without any consideration for these cases, your function probably causes an error or returns the wrong result in the...
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...