Skip to content
Exercise · Arrays · lesson 12 of 13

Exercise: without a value

Write a function function without(nums, value) that returns a new array of the elements of nums that are not equal to value, in their original order. The function does not change the array nums itself, and the result is always a new array, even when there is nothing to remove.

  • without([1, 2, 3, 2], 2) → [1, 3]
  • without([1, 2, 3], 5) → [1, 2, 3]
  • without([4, 4], 4) → []

Constraints: nums holds from 0 to 1000 integers, and value is an integer; it may occur in the array several times or not at all; after the call, nums holds the same elements in the same order.

Do not add extra imports unless the task says so explicitly.

without.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way