Jaccard similarity in basis points

A free easy coding practice problem from ml. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.

Difficulty
Easy
Type
Function
Topic
Ml
Languages
JavaScript, TypeScript or Python

Problem

Compare two short texts by their sets of words. A text's word set is: lowercase it, split it on spaces (one or more), drop empty pieces, and keep each distinct word once. The Jaccard similarity is |A ∩ B| / |A ∪ B|. Return it in basis points rounded DOWN: floor(10000 × |A ∩ B| / |A ∪ B|). If both sets are empty, return 10000. Texts contain letters, digits and spaces only, at most 1 000 characters.

Function signature

// JavaScript
function jaccardBp(a, b)

// TypeScript
function jaccardBp(a: any, b: any): any

// Python
def jaccard_bp(a, b):

Examples

  1. jaccardBp("the cat sat", "the cat ran") → 5000
  2. jaccardBp("Data science", "data SCIENCE data") → 10000
  3. jaccardBp("a b c", "x y z") → 0

How checking works

Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.

More practice problems

Next steps