Underscore.js (1.13.1) contains - working in CoCo python

javascript first:

// Underscore.js (1.13.1) contains 
// _.contains(list, value, [fromIndex]) Aliases: include, includes
// Returns true if the value is present in the list. Uses indexOf internally,
// if list is an Array. Use fromIndex to start your search at a given index.

// _.contains([1, 2, 3], 3);
// => true

let phrase = "it's OK",
    search = "OK";
if (_.include(phrase,search))
    console.log ("_.include: ",phrase,search);
// if (_.includes(phrase,search)) // not working in CoCo 
//     console.log (search);
if (_.contains(phrase,search))
    console.log ("_.contains: ",phrase,search);
    
if (phrase.includes(search)) // js
    console.log ("phrase.includes: ",phrase,search);

// output
//  _.include:  it's OK OK 
// _.contains:  it's OK OK 
// phrase.includes:  it's OK OK

then python:

phrase = "it's OK"
search = "OK"
if _.contains(phrase,search):
    console.log ("_.contains: ",phrase,search)
# output:
# _.contains:  it's OK OK

image
the help is wrong even for javascript , contains must be replaced with includes

1 Like

// Underscore.js (1.13.1) contains 
// _.contains(list, value, [fromIndex]) Aliases: include, includes
// Returns true if the value is present in the list. Uses indexOf internally,
// if list is an Array. Use fromIndex to start your search at a given index.

// _.contains([1, 2, 3], 3);
// => true

let phrase = "it's OK",
    search = "OK";
if (_.include(phrase,search))
    console.log ("_.include: ",phrase,search);
// if (_.includes(phrase,search)) // not working in CoCo 
//     console.log (search);
if (_.contains(phrase,search))
    console.log ("_.contains: ",phrase,search);
    
if (phrase.includes(search)) // js
    console.log ("phrase.includes: ",phrase,search);

// output
//  _.include:  it's OK OK 
// _.contains:  it's OK OK 
// phrase.includes:  it's OK OK

Just formatted it into JavaScript instead of the default Python formatting using some hacky HTML editing.